从 Pandas 中的重采样获取索引

Getting index from resample in Pandas

我在 Python 中有一个时间序列数据帧,频率为每秒一次。我正在尝试聚合数据以获得每分钟 Speed 的最大值。我正在使用此代码:

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()

但是,我还有另一列 Speed,我有兴趣在每分钟将它的关联值设为最大值 Acceleration。例如,假设 13:15 的最高 Acceleration 发生在 13:15:10 并且是 1.2 m/s^2。同一秒,速度5m/s。除了最大加速度之外,我还想获得该速度。谢谢。

用你自己的例子试试这个

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