Created
November 3, 2020 00:54
-
-
Save yeiichi/57500f721a837b984e73c1c356af2a41 to your computer and use it in GitHub Desktop.
Concatenates Exel files into a DataFrame
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
#!/usr/bin/env python | |
# coding: utf-8 | |
import pandas as pd | |
from pathlib import Path | |
def excel_cat(my_dir): | |
"""Concatenates Exel files into a DataFrame""" | |
# Make a list of Excel files in the file path | |
excel_dir = Path(my_dir) | |
excel_list = list(excel_dir.glob('*xlsx')) | |
# Convert each excel to Pandas DataFrame | |
list_df = [pd.read_excel(each_excel) for each_excel in excel_list] | |
# Concatenate the DFs into a single DF. | |
df = pd.concat(list_df) | |
return df | |
if __name__ == '__main__': | |
file_dir = input('Excel path? >> ') | |
print(excel_cat(file_dir).head()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment