resample
的文档说,可以使用DateOffset
作为规则。
但是有时尝试这样做会导致NotImplementedError
。
resample('2M')
有效。resample(pd.offsets.MonthEnd(2))
也可以。resample(pd.offsets.DateOffset(months=2))
失败了。此处是要复制的代码:
idx = pd.date_range('20190101', periods=14, freq='3W')
s = pd.Series(range(len(idx)), index=idx)
s.resample(pd.offsets.DateOffset(months=2)).mean()
踪迹:
Traceback (most recent call last):
....
File "....core\generic.py", line 8449, in resample
level=level,
File "....core\resample.py", line 1305, in resample
tg = TimeGrouper(**kwds)
File "....core\resample.py", line 1378, in __init__
rule = freq.rule_code
File "....tseries\offsets.py", line 442, in rule_code
return self._prefix
File "....tseries\offsets.py", line 438, in _prefix
raise NotImplementedError("Prefix not defined")
NotImplementedError: Prefix not defined
我对resample
仅支持某些DateOffsets
表示正确吗?
不支持/不支持什么类型?