File size: 727 Bytes
9963a74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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")