I am new to coding and currently i want to create individual dataframes from each excel tab. It works out so far by doing a search in this forum (i found a sample using dictionary), but then i need one more step which i can't figure out.
This is the code i am using:
import pandas as pd
excel = 'sample.xlsx'
xls = pd.ExcelFile(excel)
d = {}
for sheet in xls.sheet_names:
print(sheet)
d[f'{sheet}'] = pd.read_excel(xls, sheet_name=sheet)
Let's say i have 3 excel tabs called 'alpha', 'beta' and 'charlie'.
the code above will gave me 3 dataframes and i can call them by typing: d['alpha']
, d['beta']
and d['charlie']
.
What i want is to rename the dataframes so instead of calling them by typing (for example) d['alpha']
, i just need to write alpha
(without any other extras).
Edit: The excel i want to parse has 50+ tabs and it can grow Edit 2: Thank you all for the links and the answers! it is a great help