python - TypeError:不可散列的类型:'numpy.ndarray
问题描述
运行此代码时,我不断收到 TypeError: unhashable type: 'numpy.ndarray' 。我无法确定问题所在。
当我做 .head() 这就是我得到的:
|Year|Chinese|Malay|Indian|Others|
|----+-------+-----+------+------|
|2010| 96| 87.9| 92| 87.7|
|2011| 96.3| 89.3| 92.5| 91.7|
|2012| 97.1| 91| 92.5| 92.6|
|2013| 97.2| 91.7| 92.3| 93.6|
|2014| 97.5| 93.5| 93.2| 93.5|
我的代码:
df_tertiary = pd.read_csv('percentage-of-p1-cohort-that-progressed-to-post-secondary-education.csv',index_col=0);
df_tertiary_chi = df_tertiary[df_tertiary.race == 'Chinese']
df_tertiary_malay = df_tertiary[df_tertiary.race == 'Malay']
df_tertiary_indian = df_tertiary[df_tertiary.race == 'Indian']
df_tertiary_others = df_tertiary[df_tertiary.race == 'Others']
df_tertiary_total = pd.concat([df_tertiary_chi['percentage_p1_cohort_post_sec'],df_tertiary_malay['percentage_p1_cohort_post_sec'],df_tertiary_indian['percentage_p1_cohort_post_sec'],df_tertiary_others['percentage_p1_cohort_post_sec']], axis=1, sort=False)
df_tertiary_total.columns = ['Chinese','Malay','Indian','Others']
df_tertiary_total = df_tertiary_total.loc['2010':'2019']
df_tertiary_total = pd.DataFrame(df_tertiary_total)
display(df_tertiary_total.head())
plt.plot(df_tertiary_total)
plt.show()
错误:
TypeError Traceback (most recent call last)
<ipython-input-200-1000efab126d> in <module>
14 display(df_tertiary_total.head())
15
---> 16 plt.plot(df_tertiary_total)
17 plt.show()
数据样本
Chinese Malay Indian Others
year
2016 97.8 93.1 93.8 93.9
解决方案
推荐阅读
- r - for循环加载多个RData文件
- python - POP Random % of data from Dictionary
- python-3.x - 无论如何要从列表中删除非字母数字元素?
- java - 无法使用 JDBC 和 Spring 连接到 MySQL
- azure - 为什么在 addKey/addPassword 请求期间,Azure 广告应用程序中的证书/客户端机密会消失?
- azure-data-lake - 将单个 json 从 azure iot hub 存储到 datalake2
- java - @Sneaky Throws 在龙目岛的应用
- android - 在后台线程中使用 MPAndroidChart 会引发 java.lang.RuntimeException:无法在未调用 Looper.prepare() 的线程内创建处理程序
- html - 如何在css中居中多个按钮?
- javascript - 如何将选择链接到我的表头?