Pandas Dataframes Resample Over Uneven Periods / Minutes
searched for it but found no solution - if there is already one sry for asking but i would be thankful for a link I have a dataframe (df) like this: timestamp value 2016-0
Solution 1:
Check this I used rolling which will roll over the given frequency and do the mathematical operations like sum,mean etc. In this you need to know the start and end datetime values.
Code:
df.timestamp=pd.to_datetime(df.timestamp)
df.set_index('timestamp',inplace=True)
df = df.rolling('15s').mean()
mask = pd.date_range('2016-03-11 07:37:40','2016-03-11 07:38:05',freq='10S')
df = df.loc[mask]
df
value
2016-03-11 07:37:40 24.601800
2016-03-11 07:37:50 24.602767
2016-03-11 07:38:00 24.598067
Use your desired window instead of '15s' in rolling as well as date_range that I used.Let me know this works for you.
Post a Comment for "Pandas Dataframes Resample Over Uneven Periods / Minutes"