Assume that you have multiple CSV files located in a specific folder, and you want to concatenate all of them in a Pandas Data Frame. We assume that our CSV files are under the “My_Folder
“.
import os import pandas as pd # create an empty pandas data frame df = pd.DataFrame() # iterate over all files within "My_Folder" for file in os.listdir("My_Folder"): if file.endswith(".csv"): df = pd.concat([df , pd.read_csv(os.path.join("My_Folder", file))], axis=0 ) # reset the index df.reset_index(drop=True, inplace=True) df
Now the df
consists of the CSV
files within `My_Folder`.