简体   繁体   中英

How to merge multiple csv files and copy the data into an existing txt file

I have multiple folders and each folder contain 4 csv files with each file containing one column of data. For each folder, I want to merge these files together in a way that new dataframe will carry 4 columns from those csv files. Next I want to copy these 4 columns into an existing txt file that already has 3 columns. So the 4 columns (from csv files) will be placed next to existing columns. This operation will be done for multiple folders. I will greatly appreciate some help.

  • You can use pandas for it.

You can use this link: https://stackoverflow.com/a/21232849/4561068 to make a list of ALL the csv filename and make a dataframe out of each and append of a list of dataframes, and then at the end of iterating through all of them, you can concatenate all the dataframe in that list together as shown in the link.

Afterward, you can simply write the dataframe to a txt file.

Hope that helps!!

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