×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: Chelsea Trotter
Added: Mar 21, 2022 7:33 PM
Modified: Mar 21, 2022 7:33 PM
Views: 402
  1. def read_excel_with_multiple_sheets(file):
  2.     if file.endswith(('.xlsm', '.xlsx')):
  3.         num_sheets = len(pd.ExcelFile(file).sheet_names)
  4.         df = pd.DataFrame()
  5.         for i in range(num_sheets):
  6.             excel_data = pd.read_excel(file, sheet_name=i, comment='#')
  7.             df = pd.concat([df, excel_data], axis=0)
  8.         return df
  9.  
  10.     raise "File is not in excel format"
  11.