주어진 csv 파일의 특정 열에 대한 히스토그램과 산점도를 플로팅하려고합니다. 나는 프로그래밍에 익숙하지 않고 친구로부터이 코드를 얻었지만 분명히 작동하지만 어떻게 든이 오류가 발생합니다. 코드는 다음과 같습니다파이썬에서 CSV 파일의 열에 대한 히스토그램 그리기
import csv
import numpy as np
import matplotlib.pyplot as plt
f = open('Data for question 13.csv')
data = csv.reader(f)
Area = []; MajorAxisLength = []; MinorAxisLength = []; Perimeter = []
MinIntensity = []; MeanIntensity = []; MaxIntensity = []
header = [Area, MajorAxisLength, MinorAxisLength,Perimeter,MinIntensity,MeanIntensity,MaxIntensity]
for row in data:
i = 1
for name in header:
name.append(row[i])
i = i + 1
plt.figure()
plt.hist(Area, bins=50) # error follows after this
오류 :
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
plt.hist(Area, bins=50, alpha=0.5)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py", line 2827, in hist
stacked=stacked, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 8312, in hist
xmin = min(xmin, xi.min())
File "/Library/Python/2.7/site-packages/numpy-1.9.0-py2.7-macosx-10.9-intel.egg/numpy/core/_methods.py", line 29, in _amin
return umr_minimum(a, axis, None, out, keepdims)
TypeError: cannot perform reduce with flexible type
내가이 오류를 제거 할 수 없습니다입니다. 대답은 간단해야하지만 나는 새로운 것이므로 어떻게 대처해야할지 전혀 모른다.
. 데이터 파일은 어떻게 생겼습니까? – matsjoyce
데이터를 공유하거나 업로드하여 데이터가 어떻게 보이는지 확인할 수있는 방법이 있습니까? 이것은 당신에게 어떤 아이디어가 주어지면 도움이 될지 모르겠다. 약 400 행까지 헤더와 수치 데이터가있는 9 개의 열이있다. –
처음 몇 줄을 질문에 붙여 넣거나 (예 : ~ 10), 예를 들어 사용하십시오. [pastebin] (http://pastebin.com) 및 questtion에 링크를 넣어 – hitzg