I have a time series data frame in Python with every second frequency. I am trying to aggregate the data to get the maximum value of Speed
at each minute. I am using this code:
df = pd.DataFrame({ 'Speed' : [],
'Acceleration' : []
})
rng = pd.date_range('1/1/2011', periods=72, freq='s')
df['Speed'] = np.random.randn(len(rng))
df['Acceleration'] = np.random.randn(len(rng))
df = df.set_index(rng)
df['Acceleration'].resample("1Min").max()
However, I have another column Speed
and I am interested to get the associated value of it to the maximum Acceleration
at each minute. For example, imagine the highest Acceleration
for 13:15
happened at 13:15:10 and it was 1.2
m/s^2. At the same second, the speed was 5
m/s. I'd like to get that speed in addition to the maximum Acceleration. Thanks.
Try this using your own example
In [17]: idx = df.resample('1Min').agg({'Acceleration': np.argmax})
In [18]: df.ix[idx.Acceleration]
Out[18]:
Acceleration Speed
2011-01-01 00:00:06 2.754047 -0.274572
2011-01-01 00:01:06 3.258652 -1.302055
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.