Reputation: 925
I'm new in python and trying read each row by column index but getting KeyError: 0
while executing below code:
with open('processed/test.csv') as f:
reader = csv.DictReader(f)
for row in reader:
print row[0]
Does any one have idea how to read column by index?
Upvotes: 1
Views: 1895
Reputation: 2973
Why do you use DictReader, if you want to get row by index? Maybe your code should look like this?
with open('processed/test.csv') as f:
reader = csv.reader(f)
for row in reader:
print ', '.join(row)
if len(row):
print row[0]
Upvotes: 4