Created
August 23, 2020 19:24
-
-
Save martyychang/9fd339632c3436c94356361c353f8723 to your computer and use it in GitHub Desktop.
Combine multiple CSV files into a single CSV file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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