Created
December 7, 2020 20:39
-
-
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
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
| 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