如何用pandas得到一个连续的分钟聚合?
How to get a continuous minutely aggregate with pandas?
我有一个数据库 table,其中包含一个日期时间列,其值超过 24 小时。如果我使用 pandas dataframe groupby 函数进行逐分钟聚合,这会将所有内容放入 0-59 桶中,无论它们处于哪个小时。
如何在 table 的时间范围内逐分钟聚合,在本例中为 24 小时?此外,对于 table 中没有值的那些分钟,我如何将那一分钟的零计数插入到数据帧中?
尝试使用 pd.TimeGroupper
import pandas as pd
df = pd.DataFrame(index=pd.date_range("11:00", "21:30", freq="100ms"))
df['x'] = 1
g = df.groupby(pd.TimeGrouper('S')).sum()
我有一个数据库 table,其中包含一个日期时间列,其值超过 24 小时。如果我使用 pandas dataframe groupby 函数进行逐分钟聚合,这会将所有内容放入 0-59 桶中,无论它们处于哪个小时。
如何在 table 的时间范围内逐分钟聚合,在本例中为 24 小时?此外,对于 table 中没有值的那些分钟,我如何将那一分钟的零计数插入到数据帧中?
尝试使用 pd.TimeGroupper
import pandas as pd
df = pd.DataFrame(index=pd.date_range("11:00", "21:30", freq="100ms"))
df['x'] = 1
g = df.groupby(pd.TimeGrouper('S')).sum()