I have a list for example fruitList = [Apple, Mango, Banana]
. I have a csv file which contains a bunch of columns that includes the ones in the list.
For example:
Orange Apple Strawberry Banana
1 12 5 11
2 3 10 9
How to I get a column of csv for example Banana as list?
What I tried so far:
data_file = open('fruit_data.csv')
data_reader = csv.reader(data_file, delimiter=",")
header = data_reader.next()
my_list = []
for field in header:
for fruits in fruitList:
if(fruits==field):
mylist = header[fruits]
I know the last line of the code is wrong. I was wondering how to get the information in csv with the string variable as list index.
Thanks!