I want to add a new column to the beginning of a csv file, and I thought iterating through each row and just adding together a list containing my new column's content and the old list would work, and it does, but it only works inside the loop. Why is it doing that?
file:
column1 column2 column3
x1 y1 z1
x2 y2 z2
intended output:
0 column1 column2 column3
0 x1 y1 z1
0 x2 y2 z2
code:
import csv
x = open('C:/Documents and Settings/admin/Desktop/sample.csv')
y = csv.reader(x)
z = []
for row in y:
z.append(row)
for n in z:
n = ['0'] + n
print(n)
for m in z:
print(m)
what I get:
[0, column1, column2, column2]
[0, x1, y1, z1]
[0, x2, y2, z2]
[column1, column2, column2]
[x1, y1, z1]
[x2, y2, z2]
The zeros basically disappear outside that loop. Why?
Thanks!