如何总结每 5 秒的时间序列数据的每一列

How can I sum up each columns of Time-Series Data per 5sec

我是 pandas 的新手,想修改下面的数据透视表 table。

beacon_name 6   12  16  23  24
detected_at                                                     
08:00:00    -86.500000  -150.000000 -150    -86.500000  -85.000000  
08:00:01    -78.500000  -150.000000 -150    -88.000000  -88.000000
08:00:02    -82.750000  -150.000000 -150    -81.500000  -87.333333
08:00:03    -83.333333  -150.000000 -150    -81.000000  -83.000000
08:00:04    -87.000000  -150.000000 -150    -86.400000  -84.000000
08:00:05    -88.333333  -150.000000 -150    -79.333333  -85.000000
08:00:06    -90.000000  -150.000000 -150    -85.750000  -86.750000
08:00:07    -150.000000 -150.000000 -150    -84.000000  -88.333333...

具体来说,我想将每 5 个数据行汇总到下面的数据透视表 table 中。

beacon_name 6   12  16  23  24
detected_at                                                     
08:00:00     -418.05     -750     -750     -423.4     -427.3
08:00:05     -688.33     -750     -750     -417.22    -426.5

我搜索并尝试了几种方法,但无法获得正确的输出。

我相信你需要resample, but first convert times to timedeltas by to_timedelta:

df.index = pd.to_timedelta(df.index)
df = df.resample('5S').sum()
print (df)
                 6     12   16     23     24
beacon_name                                 
08:00:00    -418.1 -750.0 -750 -423.4 -427.3
08:00:05    -328.3 -450.0 -450 -249.1 -260.1