my CSV looks like
John,Bomb,Dawn
3,4,5
3,4,5
3,4,5
I want to add an identifier column in front so:
ID,John,Bomb,Dawn
1,3,4,5
2,3,4,5
3,3,4,5
using an enumeration function, but I don't know how to do this. Here is my code:
import csv
with open("testi.csv", 'rb') as input, open('temp.csv', 'wb') as output:
reader = csv.reader(input, delimiter = ',')
writer = csv.writer(output, delimiter = ',')
all = []
row = next(reader)
row.append('ID')
all.append(row)
count = 0
for row in reader:
count += 1
while count:
all.append(row)
row.append(enumerate(reader, 1))
break
writer.writerows(all)
And the result does not come like this:
John,Bomb,Dawn,ID
3,4,5,<enumerate object at 0x7fb2a5728d70>
3,4,5,<enumerate object at 0x1764370>
3,4,5,<enumerate object at 0x17643c0>
So, the identifier comes at the end, when it should be at the beginning, and it does not even do 1,2,3. Some strange error comes up.