【发布时间】:2021-04-02 08:09:16
【问题描述】:
rand_val new_val copy_time
2020-10-15 00:00:00 7 26 2020-10-15 00:00:00
2020-10-15 00:00:10 8 29 2020-10-15 00:00:10
2020-10-15 00:00:20 1 53 2020-10-15 00:00:20
2020-10-15 00:03:50 6 69 2020-10-15 00:03:50
2020-10-15 00:04:00 3 19 2020-10-15 00:04:00
我正在使用 resample 方法对时间序列进行下采样。我发现在聚合数据上应用函数时无法调用特定列。
假设我想做一些涉及调用列名的操作:
df.resample("1min").apply(lambda x: sum(x.rand_val) if len(x)>1 else 0)
我收到一个错误:
AttributeError: 'Series' object has no attribute 'rand_val'
如果我对其他变量进行了 groupby,这将是可能的。我猜重采样功能不一样。有什么想法吗?
【问题讨论】:
-
试试
df.resample('1min',on='copy_time').apply(...)
标签: python pandas time-series pandas-groupby downsampling