Last active
December 22, 2019 17:21
-
-
Save rahulsainani/e7e2a0ce1b52cbe404673ac1ff6bb35f to your computer and use it in GitHub Desktop.
This file contains 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
import os | |
import glob | |
import pandas as pd | |
def combine_csv(): | |
"""Combine all files in the list and export to CSV""" | |
os.chdir("<directory_where_all_csvs_are>") | |
extension = 'csv' | |
all_file_names = [i for i in glob.glob('*.{}'.format(extension))] | |
# Read all CSVs in the directory | |
list_csv = [pd.read_csv(f, encoding='UTF-16') for f in all_file_names] | |
combined_csv = pd.concat(list_csv) | |
combined_csv.to_csv( | |
"combined_csv.csv", | |
index=False, | |
encoding='utf-8-sig' | |
) | |
def main(): | |
combine_csv() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment