Group Pandas Time-series Data Frame Using Specific Time Intervals
I have a large csv file with time stamp data in the iso format 2015-04-01 10:26:41. The data span multiple months with entries ranging from 30 secs apart to multiple hours. It's co
Solution 1:
First, it looks like you read a blank row. You probably want to skip the first row in your file pd.read_csv(filename, skiprows=1)
.
You should convert the text representation of the time into a DatetimeIndex using pd.to_datetime()
.
df.set_index(pd.to_datetime(df['time']), inplace=True)
You should then be able to resample.
df.resample('15min', how=np.mean)
Solution 2:
Alexander's answer is correct; also note that you can do
df = pd.read_csv('myfile.csv', parse_dates=True)
And your date column should have the datetime type if the format is sane. Then you can set the index and resample as above.
Post a Comment for "Group Pandas Time-series Data Frame Using Specific Time Intervals"