Python Loop through Excel sheets, place into one df - Stack Overflow | thiscodeWorks

PHOTO EMBED

Tue Jul 23 2024 15:34:32 GMT+0000 (Coordinated Universal Time)

Saved by @knguyencookie

import pandas as pd
 
sheets_dict = pd.read_excel('Book1.xlsx', sheetname=None)
 
full_table = pd.DataFrame()
for name, sheet in sheets_dict.items():
    sheet['sheet'] = name
    sheet = sheet.rename(columns=lambda x: x.split('\n')[-1])
    full_table = full_table.append(sheet)
 
full_table.reset_index(inplace=True, drop=True)
 
print full_table
content_copyCOPY

https://www.thiscodeworks.com/python-loop-through-excel-sheets-place-into-one-df-stack-overflow-python/5ff5c97426c684001453b627