Skip to content

Instantly share code, notes, and snippets.

@martyychang
Created August 23, 2020 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martyychang/9fd339632c3436c94356361c353f8723 to your computer and use it in GitHub Desktop.
Save martyychang/9fd339632c3436c94356361c353f8723 to your computer and use it in GitHub Desktop.
Combine multiple CSV files into a single CSV file
# https://blog.softhints.com/how-to-merge-multiple-csv-files-with-python/
# https://www.techbeamers.com/pandas-merge-csv-files/
import os, glob
import pandas as pdlib
path = "/Users/mchang/Desktop/Salesforce/Account/1598097614646/"
list_of_files = glob.glob(os.path.join(path, "data_*.csv"))
# Consolidate all CSV files into one object
result_obj = pdlib.concat([pdlib.read_csv(file) for file in list_of_files])
# Convert the above object into a csv file and export
result_obj.to_csv(os.path.join(path, 'data.csv'), index=False, encoding="utf-8")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment