I'm attempting to create a 10 minute running average of wind speeds in order to plot on a graph. My data has numerous uneven time steps within it. I am currently using the CSV module to read in and gather my data, I am not very familiar with pandas and have had issues in the past with it.
import matplotlib.pyplot as plt
import csv
from datetime import datetime
x=[]
y=[]
with open('KART_201901010000_201912310000.txt') as csvfile:
plots = csv.reader(csvfile, delimiter=',')
for row in plots:
if 'M' == row[1]:
continue
else:
x.append(datetime.strptime(row[0],'%Y-%m-%d %H:%M'))
y.append(int(row[1]))
plt.plot(x,y, label='Wind Speed')
plt.xlabel('Date and Time')
plt.ylabel('Wind Speed (Kts)')
plt.title('Wind Speed\nVersus Time')
plt.legend()
plt.show()
Here is a snippet of my data set showing one of the many uneven time steps.
2019-11-01 11:40,30
2019-11-01 11:45,35
2019-11-01 11:50,32
2019-11-01 11:55,34
2019-11-01 11:56,33
2019-11-01 12:00,33
2019-11-01 12:05,36
2019-11-01 12:10,31
The obvious general idea is to use a for loop to continue the calculations that I would need to average the data. The issue I am running into is how do I account for the uneven steps? Is there a way to use datetime to achieve this that I have no idea about?