Skip to content

Instantly share code, notes, and snippets.

@bdunnette
Created December 7, 2020 20:39
Show Gist options
  • Select an option

  • Save bdunnette/6faa84c5e9bc5cec3d345766598aea77 to your computer and use it in GitHub Desktop.

Select an option

Save bdunnette/6faa84c5e9bc5cec3d345766598aea77 to your computer and use it in GitHub Desktop.
quick-and-dirty script to merge multiple Excel files into a single CSV
import os
from pathlib import Path
import pandas as pd
OUTFILE = 'merged.csv'
ENGINE = 'openpyxl'
cwd = os.getcwd()
p = Path(cwd)
xlsx_files = list(p.glob('*.xlsx'))
for idx, val in enumerate(xlsx_files):
df = pd.read_excel(val, engine=ENGINE)
if idx == 0:
df.to_csv(OUTFILE, index=False)
else:
df.to_csv(OUTFILE, index=False, mode='a', header=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment