Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to join or combine multiple csv files with concatenate and export dataframe to csv format

import pandas as pd
import glob
import os
os.chdir("C:/Users/DONPECH/Desktop/PROJECTS/AIRLINE RESEARCH/RESEARCH/DATASET/flight")

# setting the path for joining multiple files
files = os.path.join("C:/Users/DONPECH/Desktop/PROJECTS/AIRLINE RESEARCH/RESEARCH/DATASET/flight", "On_Time_On_Time_Performance_2015_*.csv")

# list of merged files returned
files = glob.glob(files)

print("Resultant CSV after joining all CSV files at a particular location...");

# joining files with concat and read_csv
df = pd.concat(map(pd.read_csv, files),ignore_index=True)

#export DataFrame to CSV file
df.to_csv(r'C:UsersDONPECHDesktopPROJECTSAIRLINE RESEARCHRESEARCHDATASETflightflights.csv', index=False)
print(df)
 
PREVIOUS NEXT
Tagged: #How #join #combine #multiple #csv #files #concatenate #export #dataframe #csv #format
ADD COMMENT
Topic
Name
5+3 =