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?
csv
? I thinknp.loadtxt
would do a better job here (simpler code, automatic conversion, etc).skiprows=1
toloadtxt
to have it skip the column headers. However, thecsv
module will handle csv files with quoted strings containing commas, etc.loadtxt
is (deliberately) not set up to deal with non-simple delimiters.