美文网首页
Pandas降采样print(ts.resample('3M')

Pandas降采样print(ts.resample('3M')

作者: MayerBin | 来源:发表于2019-08-10 17:42 被阅读0次

报错信息

IncompatibleFrequency: Frequency <MonthEnd>
 cannot be resampled to <3 * MonthEnds>, as they are not sub or super periods

源代码

prng = pd.period_range('2016','2017',freq = 'M')
ts = pd.Series(np.arange(len(prng)), index = prng)
print(ts)

print(ts.resample('3M').sum())  # 降采样

修改后的代码

rng = pd.period_range('2016','2017',freq = 'M')
ts = pd.Series(np.arange(len(prng)), index = prng)
print(ts)
# 修改部分
td.index = td.index.astype('datetime64[ns]')
print(td.resample('3M', kind='period').sum())     # 降采样

相关文章

网友评论

      本文标题:Pandas降采样print(ts.resample('3M')

      本文链接:https://www.haomeiwen.com/subject/pznrjctx.html