I have a large csv file and I want to get all the values ββin it that are stored in certain columns, I know the name.
Somehow I donβt understand how to do this, but I think I'm close :(
import codecs
import csv
import json
import pprint
import re
FIELDS = ["name", "timeZone_label", "utcOffset", "homepage","governmentType_label", "isPartOf_label", "areaCode", "populationTotal",
"elevation", "maximumElevation", "minimumElevation", "populationDensity", "wgs84_pos#lat", "wgs84_pos#long",
"areaLand", "areaMetro", "areaUrban"]
index=[]
with open('/Users/stephan/Desktop/cities.csv', "r") as f:
mycsv=csv.reader(f)
results=[]
headers=None
for row in mycsv:
for i, col in enumerate(row):
if col in FIELDS:
index.append(i)
print row[i]
print index
My list index, correctly, I think and gives me the correct values ββ(column indexes)
What do I need to add to my code for it to work?
source
share