简体   繁体   中英

How to add a add a value to a pre-existing row in a csv file using python

So I am trying to add a value to a pre-existing row in a csv file using python. I have literally scoured the web for any websites, previous StackOverflow Questions which have the answer I am looking for. But I can't find any. So basically, I want to change a csv file from

example,example,example
example2,example2,example2

to

example,example,example,example
example2,example2,example2,example2

I don't have any code because I have no idea how I could possibly do it.

if you want to add column to the last row only you can just append it like this

with open("file.csv","a") as csv_file:
    csv_file.write(",example2")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM