Skip to content

Instantly share code, notes, and snippets.

@ajomathew
Created November 19, 2020 09:48
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 ajomathew/434efea87652ff9a553585d56d9f2d4e to your computer and use it in GitHub Desktop.
Save ajomathew/434efea87652ff9a553585d56d9f2d4e to your computer and use it in GitHub Desktop.
Generate a excel sheet from csv files located in a from same folder
import pandas as pd
import numpy as np
import os, fnmatch
listofcsvs = os.listdir(".")
pattern = "*.csv"
GNF = pd.ExcelWriter('Consolidated.xlsx')
for file in listofcsvs:
if fnmatch.fnmatch(file, pattern):
print(file)
df_csv = pd.read_csv(file)
df_csv.to_excel(GNF, sheet_name=file.split('.')[1], index=False)
GNF.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment