首页 > 解决方案 > Pandas 重新采样错误:resample() 得到了一个意外的关键字参数“偏移量”

问题描述

我正在尝试重新采样数据框,并且我想抵消数据。我收到错误:

resample() got an unexpected keyword argument 'offset'

我尝试运行 pandas文档中的示例代码。

start, end = '2000-10-01 23:30:00', '2000-10-02 00:30:00'
rng = pd.date_range(start, end, freq='7min')
ts = pd.Series(np.arange(len(rng)) * 3, index=rng)

ts.resample('17min', offset='23h30min').sum()

这会导致相同的错误。我已将 pandas 升级到当前的最新版本('1.0.3')。

更新:

在文档中,在偏移下它声明“1.1.0 版中的新功能”。

标签: pythonpandas

解决方案


解决方案是安装pandas 1.1.0。可以通过从源代码构建熊猫来完成。

从 github 克隆开发版的 pandas:

git clone https://github.com/pandas-dev/pandas/releases

安装cython:

pip install cython

cd pandas,然后:

python -m pip install -e . --no-build-isolation --no-use-pep517


推荐阅读