I have a csv file and I have to calculate the average value for some columns. Here is how I did it:
file=csv.reader(open('tab.csv','r')) n=[] for row in file: n.append(row[8])
So I have a list of strings: n = ['', '', '1.58' ...] How can I convert them to float? I tried:
n_values=np.array(n) n_values[n=='']='0' values=n_values.astype(np.float) np.mean(values)
But the average value is wrong, because I have to skip empty lines, not counting. Thanks for the help!
Alice source share