I'm trying to extract a bunch of lines from a CSV file and write them into another, but I'm having some problems.
import csv
f = open("my_csv_file.csv", "r")
r = csv.DictReader(f, delimiter=',')
fieldnames = r.fieldnames
target = open("united.csv", 'w')
w = csv.DictWriter(united, fieldnames=fieldnames)
while True:
try:
row = r.next()
if r.line_num <= 2: #first two rows don't matter
continue
else:
w.writerow(row)
except StopIteration:
break
f.close()
target.close()
Running this, I get the following error:
Traceback (most recent call last):
File "unify.py", line 16, in <module>
w.writerow(row)
File "C:\Program Files\Python25\lib\csv.py", line 12
return self.writer.writerow(self._dict_to_list(row
File "C:\Program Files\Python25\lib\csv.py", line 12
if k not in self.fieldnames:
TypeError: argument of type 'NoneType' is not iterable
Not entirely sure what I'm dong wrong.