Skip to content

Instantly share code, notes, and snippets.

@AsthaSharma1
Created July 7, 2021 14:23
Show Gist options
  • Save AsthaSharma1/3d16005348f0122fb0ccb6709aeba8fb to your computer and use it in GitHub Desktop.
Save AsthaSharma1/3d16005348f0122fb0ccb6709aeba8fb to your computer and use it in GitHub Desktop.
import os
import glob
import pandas as pd
os.chdir("/mydir")
extension = 'csv'
all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
#combine all files in the list
combined_csv = pd.concat([pd.read_csv(f) for f in all_filenames ])
#export to csv
combined_csv.to_csv( "combined_csv.csv", index=False, encoding='utf-8-sig')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment