pandas.core.groupby.DataFrameGroupBy.resample#
- DataFrameGroupBy.resample(rule, *args, **kwargs)[源代码]#
在使用TimeGrouper时提供重采样。
给定一个分组,该函数根据字符串“字符串”->“频率”对其进行重采样。
请参阅 frequency aliases 文档以了解更多详细信息。
- 参数
- rule字符串或日期偏移量
表示目标分组转换的偏移量字符串或对象。
- *args, ** 科瓦格人
可能的论据有 how , fill_method , limit , kind 和 on ,以及其他有关 TimeGrouper 。
- 退货
- 石斑鱼
返回一个新的石斑鱼,并附上我们的重采样器。
参见
Grouper
指定按关键字分组时要重新采样的频率。
DatetimeIndex.resample
时间序列的频率变换和重采样。
示例
>>> idx = pd.date_range('1/1/2000', periods=4, freq='T') >>> df = pd.DataFrame(data=4 * [range(2)], ... index=idx, ... columns=['a', 'b']) >>> df.iloc[2, 0] = 5 >>> df a b 2000-01-01 00:00:00 0 1 2000-01-01 00:01:00 0 1 2000-01-01 00:02:00 5 1 2000-01-01 00:03:00 0 1
将DataFrame下采样到3分钟箱中,并将落入箱中的时间戳值求和。
>>> df.groupby('a').resample('3T').sum() a b a 0 2000-01-01 00:00:00 0 2 2000-01-01 00:03:00 0 1 5 2000-01-01 00:00:00 5 1
将该系列向上采样到30秒的箱中。
>>> df.groupby('a').resample('30S').sum() a b a 0 2000-01-01 00:00:00 0 1 2000-01-01 00:00:30 0 0 2000-01-01 00:01:00 0 1 2000-01-01 00:01:30 0 0 2000-01-01 00:02:00 0 0 2000-01-01 00:02:30 0 0 2000-01-01 00:03:00 0 1 5 2000-01-01 00:02:00 5 1
按月重新采样。值被分配给期间的月份。
>>> df.groupby('a').resample('M').sum() a b a 0 2000-01-31 0 3 5 2000-01-31 5 1
如上所述,将序列向下采样为3分钟箱,但关闭箱间隔的右侧。
>>> df.groupby('a').resample('3T', closed='right').sum() a b a 0 1999-12-31 23:57:00 0 1 2000-01-01 00:00:00 0 2 5 2000-01-01 00:00:00 5 1
将序列向下采样到3分钟的箱中,并关闭箱间隔的右侧,但使用右侧边缘而不是左侧来标记每个箱。
>>> df.groupby('a').resample('3T', closed='right', label='right').sum() a b a 0 2000-01-01 00:00:00 0 1 2000-01-01 00:03:00 0 2 5 2000-01-01 00:03:00 5 1