【问题标题】:Getting TypeError: unhashable type: 'dict_keys' in jupyter notebook获取 TypeError: unhashable type: 'dict_keys' in jupyter notebook
【发布时间】:2022-04-01 12:25:38
【问题描述】:

这是我的整个代码的一部分,我在这里得到了 Typerror。这就是我所做的。

plt.figure(figsize=(14,6))
plt.plot(data.groupby(['Country']).groups.keys(), data.groupby(['Country'])['CustomerID'].count())
plt.xticks(rotation = 90, fontsize = 14)
plt.title("Number of transanctions done for each country")
plt.ylabel("No. of trans.")
plt.xlabel("Country")
plt.show()

不知道如何解决这个错误。

【问题讨论】:

  • 发布完整错误回溯
  • 试试tuple(data.groupby(['Country']).groups.keys()) 而不是data.groupby(['Country']).groups.keys() ?

标签: python pandas machine-learning jupyter-notebook data-science


【解决方案1】:

请尝试下面的代码,字典应该作为列表传递

plt.figure(figsize=(14,6))
plt.plot(list(data.groupby(['Country']).groups.keys()), list(data.groupby(['Country'])['CustomerID'].count()))
plt.xticks(rotation = 90, fontsize = 14)
plt.title("Number of transanctions done for each country")
plt.ylabel("No. of trans.")
plt.xlabel("Country")
plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 2021-08-01
    • 2021-07-26
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    相关资源
    最近更新 更多