简体   繁体   中英

How to merge 3 columns into a new column and add resulting column to existing CSV file in Python (without using Panda)

Assume we have a file called 'teams.csv'. We want to do the operation below to all the rows in the file 'teams.csv' and return a file with the same name but now with only 3 columns instead of 5. And we also need to name our new column 'sport'. In the file '***' indicate that a person does not play that particular sport.

I have a CSV with the following columns:

旧桌子

And want the CSV file with only 3 cols as shown below

新表

You could use something like this answer to create a list of objects based on the contents of the CSV file, manipulate the data as necessary and then write back to the CSV file.

Sharing the code you have already tried would also be a good idea ;-)

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