Update existing columns and rows within csv file using Python

Posted by wilbev on Stack Overflow See other posts from Stack Overflow or by wilbev
Published on 2012-04-15T05:21:51Z Indexed on 2012/04/15 5:30 UTC
Read the original article Hit count: 143

Filed under:
|

So I've been attempting to use the csv module in Python to add data to existing rows and columns, but only specific columns of each row. So for examples let's say my existing csv file has the following:

id, name, city, age
1, Ed,, 34
2, Pat,, 23

So basically the city of each person is missing, so I would like to update each row with that person's city. However, the writerow method only seems replace the existing data within the csv file. Changing the open file to append mode just adds the data to a new row. Is there any way to skip the existing data, and only add the city to each row?

Thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about csv