从 csv 文件制作直方图
我正在尝试从 csv 文件读取一列数据并为其创建直方图。我可以将数据读入数组,但无法制作直方图。这就是我所做的:
thimar=csv.reader(open('thimar.csv', 'rb'))
thimar_list=[]
thimar_list.extend(thimar)
z=[]
for data in thimar_list:
z.append(data[7])
zz=np.array(z)
n, bins, patches = plt.hist(zz, 50, normed=1)
这给了我错误:
TypeError: cannot perform reduce with flexible type
知道发生了什么吗?
I am trying to read a column of data from a csv file and create a histogram for it. I could read the data into an array but was not able to make the histogram. Here is what I did:
thimar=csv.reader(open('thimar.csv', 'rb'))
thimar_list=[]
thimar_list.extend(thimar)
z=[]
for data in thimar_list:
z.append(data[7])
zz=np.array(z)
n, bins, patches = plt.hist(zz, 50, normed=1)
which gives me the error:
TypeError: cannot perform reduce with flexible type
Any idea what is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
修改第六行,将字符串转换为数字,
这样我就得到了一些我的虚构数据的图。
modify the sixth line to cast string to numeric
with this i got some plot with my made up data.
这里有两个选项,如果您的所有列都由数字组成,则第一个选项会起作用:
如果文件中有非数字列(即姓名、性别等),则这个选项更好:
Here are two options, this one will work if all your columns are made up of numbers:
this one is better if you have non-numeric columns in your file (ie Name, Gender, ...):