Skip to content

Instantly share code, notes, and snippets.

@rahulsainani
Last active December 22, 2019 17:21
Show Gist options
  • Save rahulsainani/e7e2a0ce1b52cbe404673ac1ff6bb35f to your computer and use it in GitHub Desktop.
Save rahulsainani/e7e2a0ce1b52cbe404673ac1ff6bb35f to your computer and use it in GitHub Desktop.
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