Very good, I am new to Python and I am now struggling with the lists.
I expose what I have developed.
Currently I have a program that loads the following data structure through a .csv file.
1,4.0,?,?,none,?
2,2.0,3.0,?,none,38
2,2.5,2.5,?,tc,39
Later I store it in a list, applying a split in the commas so that I have a list with the following form.
['1', '4.0', '?', '?', 'none', '?\n']
['2', '2.0', '3.0', '?', 'none', '38\n']
['2', '2.5', '2.5', '?', 'tc', '39\n']
Based on that list I have to calculate the average of the elements in each column, that is, the mean for example of the first would be with the elements 1, 2 and 2, the second average with the elements 4.0 2.0 and 2.5 and so on.
My question is this, how to access those elements? , until now I was doing a for of the list, but I returned each row, that is, ['1', '4.0', '?', '?', 'None', '? \ N'] and so on, but after trying different ways, I can not get back the first of the elements of each one of the rows, then the second, and so on until the characters end.
I have the following function to which I pass the list to discuss, previously commented.
To subsequently obtain the elements of the first column, then the second and so on.
def promedio(lista):
for elem in lista:
print elem
def main():
print sys.argv[1]
lista = []
with open(sys.argv[1],'r') as f:
for line in f:
lista.append(line.split(','))
print f.close()
lista.pop()
True
promedio(lista)
if __name__ == '__main__':
main()
In short, it is a main, which performs the processing of data and then passes the list to a function that calculates the average of the numerical values (not yet developed).
Any ideas? Thanks in advance.