简体   繁体   English

TypeError: unhashable type: 'numpy.ndarray' plot 图

[英]TypeError: unhashable type: 'numpy.ndarray' plot graph

I have this data as a csv我有这个数据作为 csv

Group | Man | Women

0 to 4|10000|20000
5 to 9|20000|50000
...
80+   |100  |4000

and a need to plot a bar graph, but when define the x and y and put the code plt.plot(x,y)并且需要 plot 一个条形图,但是当定义 x 和 y 并放代码plt.plot(x,y)

python returs the error unhashable type: 'numpy.ndarray' , python 返回错误unhashable type: 'numpy.ndarray'

how can I resolve?我该如何解决?

You can write to make bar chart with matplotlib:您可以使用 matplotlib 编写条形图:

import pandas as pd
import matplotlib.pyplot as plt
file = pd.read_csv('tmp.csv', sep=';', header=0)
plt.barh(file["Group"].tolist(), file["Men"].tolist())
plt.show()

or the below as alternative:或以下作为替代:

import pandas as pd
import matplotlib.pyplot as plt
file = pd.read_csv('tmp.csv', sep=';', header=0)
ax = file.plot.barh(x='Group', y='Women')
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM