Reputation: 99
I have to read this csv file into a list and I have declared type int for writing certain columns in list as integer type but this error has become a problem for me.
with open('new_toy_dataset.csv','r') as cf:
for row in cf:
toy_list.append([int(row[0]), row[1], row[2], int(row[3]), int(row[4]), row[5]])
Upvotes: 0
Views: 141
Reputation: 154
The problem is that you are not skipping the header.
import csv
toy_list = []
ind = 0
with open('new_toy_dataset.csv','r') as cf:
reader = csv.reader(cf, delimiter=';') # whatever delimiter it is
for row in reader:
if ind == 0:
ind += 1
continue
toy_list.append([int(row[0]), row[1], row[2], int(row[3]), int(row[4]), row[5]])
Upvotes: 1