Tuesday 15 May 2012

How do I make a histogram from a csv file which contains a single column of numbers in python? -



How do I make a histogram from a csv file which contains a single column of numbers in python? -

i have csv file (excel spreadsheet) of column of 1000000 numbers. want create histogram of info frequency of numbers on y-axis , number quantities on x-axis. know matplotlib can plot histogram, main problem converting csv file string float since string can't graphed. have:

import matplotlib.pyplot plt import csv open('d1.csv', 'rb') data: rows = csv.reader(data, quoting = csv.quote_nonnumeric) floats = [[item number, item in enumerate(row) if item , (1 <= number <= 12)] row in rows] plt.hist(floats, bins=50) plt.title("histogram") plt.xlabel("value") plt.ylabel("frequency") plt.show()

you can in 1 line pandas:

import pandas pd pd.read_csv('d1.csv', quoting=2)['column_you_want'].hist(bins=50)

python csv matplotlib histogram

No comments:

Post a Comment