Skip to content

Instantly share code, notes, and snippets.

@leavlzi
Created December 26, 2019 03:27
Show Gist options
  • Save leavlzi/d96d816adcdfc1d0c4b2468c8ee6cb2e to your computer and use it in GitHub Desktop.
Save leavlzi/d96d816adcdfc1d0c4b2468c8ee6cb2e to your computer and use it in GitHub Desktop.
#Below code will work even if you don't know the exact sheet_names in the excel file. You can try this:
import pandas as pd
xls = pd.ExcelFile('myexcel.xls')
out_df = pd.DataFrame()
for sheet in xls.sheet_names:
df = pd.read_excel('myexcel.xls', sheet_name=sheet)
out_df.append(df) ## This will append rows of one dataframe to another(just like your expected output)
print(out_df)
## out_df will have data from all the sheets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment