MAC下 Anaconda的TypeError: resample() got an unexpected keyword argument 'how'解决方案

Pandas中的resample,重新采样,是对原样本重新处理的一个方法,是一个对常规时间序列数据重新采样和频率转换的便捷的方法。

其中函数resample的方法格式:

 DataFrame.resample(rule, how=None, axis=0, fill_method=None, closed=None, label=None, convention='start',kind=None, loffset=None, limit=None, base=0)

将代码:

m_returns = ret_index.resample('BM',how='last').pct_change()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-125-10be9ad4be8f> in <module>()
----> 1 m_returns = ret_index.resample('BM',how='last').pct_change()

TypeError: resample() got an unexpected keyword argument 'how'

m_returns = ret_index.resample('BM').last().pct_change()
m_returns['2020']

报错的原因是函数resample‘how’参数已经不适用了,可以将resample(how='last')改成resample.last()的形式,改成代码:

m_returns = ret_index.resample('BM').last().pct_change()
m_returns['2020']
Out:
Date
2020-01-31    0.054010
2020-02-28   -0.114701
2020-03-31   -0.069761
2020-04-30    0.112785
Freq: BM, Name: Adj Close, dtype: float64
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值