I'm new in Python and I'm trying to get the average of every (column or row) of a csv file for then select the values that are higher than the double of the average of its column (o row). My file have hundreds of columns, and have float values like these:
845.123,452.234,653.23,...
432.123,213.452.421.532,...
743.234,532,432.423,...
I've tried several changes to my code to get the average for every column (separately), but at the moment my code is like this one:
def AverageColumn (c):
f=open(csv,"r")
average=0
Sum=0
column=len(f)
for i in range(0,column):
for n in i.split(','):
n=float(n)
Sum += n
average = Sum / len(column)
return 'The average is:', average
f.close()
csv="MDT25.csv"
print AverageColumn(csv)
But I always get a error like " f has no len()" or "'int' object is not iterable"...
I'd really appreciate if someone show me how to get the average for every column (or row, as you want), and then select the values that are higher than the double of the average of its column (or row). I'd rather without importing modules as csv, but as you prefer. Thanks!
csv?)return, or how to use arrays to have several computations going at once.