Temporal differentiation in Pandas

Let's say I have a data frame with multiple timestamps and values. I would like to measure Δ values / Δt every 2.5 seconds. Does Pandas provide any utilities for time differentiation?

  time_stamp values 19492 2014-10-06 17:59:40.016000-04:00 1832128 167106 2014-10-06 17:59:41.771000-04:00 2671048 202511 2014-10-06 17:59:43.001000-04:00 2019434 161457 2014-10-06 17:59:44.792000-04:00 1294051 203944 2014-10-06 17:59:48.741000-04:00 867856 
+6
source share
1 answer

It certainly does. First, you will need to convert the indexes to the pandas date_range format, and then use the custom offset functions available for the / dataframes series indexed by this class. Useful documentation here . Read more about alias offsets.

This code should reconfigure your data at 2.5 second intervals.

 #df is your dataframe index = pd.date_range(df['time_stamp']) values = pd.Series(df.values, index=index) #Read above link about the different Offset Aliases, S=Seconds resampled_values = values.resample('2.5S') resampled_values.diff() #compute the difference between each point! 

That should do it.

+6
source

Source: https://habr.com/ru/post/976387/


All Articles