Assume that you have multiple CSV files located in a specific folder, and you want to concatenate all of them and saved them to a file called merged.csv
. We can work with Pandas and use the trick with mode=a
within the .to_csv()
which means append.
import os import pandas as pd # iterate over all files within "My_Folder" for file in os.listdir("My_Folder"): if file.endswith(".csv"): tmp = pd.read_csv(os.path.join("My_Folder", file)) tmp.to_csv("merged.csv", index=False, header=False, mode='a')