# Import the os and pandas modules import os import pandas as pd # Define the directory where the csv files are located directory = "." # Create an empty list to store the data frames data_frames = [] # Loop through each file in the directory for file in os.listdir(directory): # Check if the file is a csv file if file.endswith(".csv"): # Read the csv file as a data frame and append it to the list data_frame = pd.read_csv(os.path.join(directory, file)) data_frames.append(data_frame) # Concatenate all the data frames into one merged_data_frame = pd.concat(data_frames) # Save the merged data frame as a new csv file merged_data_frame.to_csv("merged.csv", index=False, encoding="utf-8")