Data Analysis In Python

Published: 31 March 2023
on channel: Physics Lectures by Erica
131
2

A Tutorial on Analyzing/Plotting Data using Python.

Code
__________________________________________________
import csv
import numpy as np
import matplotlib.pyplot as plt


t = []
x = []
s = []

with open('speed.csv', newline='') as csvfile:
datareader = csv.reader(csvfile, delimiter=' ', quotechar='|')

for row in datareader:
print(','.join(row))
t.append(float(row[0].split(',')[0]))
x.append(float(row[0].split(',')[1]))
s.append(float(row[0].split(',')[2]))

ts = t
t = np.divide(t,60*60)

print(t)
print(x)
print(s)


plt.close('all')

plt.subplot(2,1,1)
plt.plot(ts,x,'bd-')
thefit = np.polyfit(t,x,1)
plt.plot(ts,np.multiply(t,thefit[0])+thefit[1],'r')
plt.xlabel('Time (s)')
plt.ylabel('Distance (miles)')


plt.subplot(2,1,2)
plt.plot(ts,s,'go-')
speed= np.divide(np.diff(x),np.diff(t))
plt.plot(ts[1:]-np.average(np.diff(ts))/2,speed,'rd-')
plt.xlabel('Time (s)')
plt.ylabel('Speed (mph)')

plt.show()

__________________________________________________
Data
__________________________________________________
0,0,0
14.7,0.1,38
23.1,0.2,40
31.7,0.3,39
41.8,0.4,31
55.2,0.5,30
66.1,0.6,40
74.2,0.7,41
82.1,0.8,43
90.4,0.9,40
102.7,1,20
113.5,1.1,35

________________________________________
#python #data #plotting #analysis


On this page of the site you can watch the video online Data Analysis In Python with a duration of hours minute second in good quality, which was uploaded by the user Physics Lectures by Erica 31 March 2023, share the link with friends and acquaintances, this video has already been watched 131 times on youtube and it was liked by 2 viewers. Enjoy your viewing!