import pandas as pd def read_excel_sheets(xls_path): """Read all sheets of an Excel workbook and return a single DataFrame""" print(f'Loading {xls_path} into pandas') xl = pd.ExcelFile(xls_path) df = pd.DataFrame() columns = None for idx, name in enumerate(xl.sheet_names): print(f'Reading sheet #{idx}: {name}') sheet = xl.parse(name) if idx == 0: # Save column names from the first sheet to match for append columns = sheet.columns sheet.columns = columns # Assume index of existing data frame when appended df = df.append(sheet, ignore_index=True) return df
Read more of this post
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.