【问题标题】:AttributeError: module 'pandas' has no attribute 'ewma' [duplicate]AttributeError:模块'pandas'没有属性'ewma'[重复]
【发布时间】:2020-01-29 16:28:36
【问题描述】:
mte_exp_wighted_avg = pd.ewma(mte, halflife=12)
plt.plot(mte)
plt.plot(mte_exp_wighted_avg, color='red')
plt.xticks(fontsize = 25)
plt.yticks(fontsize = 25)
plt.xlabel('Years', fontsize = 25)
plt.ylabel('CO2 Emission', fontsize = 25)
plt.title('CO2 emission by coal power generation', fontsize = 25)
plt.show()

代码如上,pandas升级了

错误如下所示

【问题讨论】:

  • 这里是错误信息------------------------- -------------------------------------- AttributeError Traceback (最近一次调用最后一次) in () ----> 1 mte_exp_wighted_avg = pd.ewma(mte, halflife=12) 2 plt.plot(mte) 3 plt.plot(mte_exp_wighted_avg, color='red') 4 plt.xticks(fontsize = 25) 5 plt.yticks(fontsize = 25) AttributeError: module 'pandas' has no attribute 'ewma'
  • 嘿,欢迎来到 SO(StackOverflow)!您可能想查看this。您也可以编辑您的帖子。因此,您可能希望将您的评论移至问题中。

标签: python pandas time-series


【解决方案1】:

Pandas 的 指数移动平均函数 (ewma) 自 Pandas 0.19 起已重命名为 ewm。这只是改变一些名字的问题:

mte_exp_wighted_avg = pd.ewm(mte, halflife=12)
plt.plot(mte)
plt.plot(mte_exp_wighted_avg, color='red')
plt.xticks(fontsize = 25)
plt.yticks(fontsize = 25)
plt.xlabel('Years', fontsize = 25)
plt.ylabel('CO2 Emission', fontsize = 25)
plt.title('CO2 emission by coal power generation', fontsize = 25)
plt.show()

【讨论】:

    【解决方案2】:

    pd.ewma(mte, halflife=12) 将不再起作用。
    ewma 已更改为 ewm
    mte_exp_wighted_avg = mte.ewm(halflife=12,min_periods=0,adjust=True,ignore_na=False).mean()

    【讨论】:

    • mte 包是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-28
    • 2019-05-23
    • 2018-09-18
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    相关资源
    最近更新 更多