'Assigning each excel sheet to a variable while looping (using openpyxl) and create dataframe of each sheets
I have an excel document with multiple sheets containing different data sets. For instance, first sheet has 2 column data where as the second sheet (sheet 2) has 3 columns. I need to iterate through the sheetnames using openpyxl or pandas and create dataframe of each sheet with its name assigned to each data frame.
How can I do this.
Can someone put your expertise here?
Thank you
Solution 1:[1]
I think you could achieve this with a simple dictionary: Take this as a hypothetical example:
import openpyxl
d = {}
wb = openpyxl.load_workbook("file.xlsx")
sheets = ['Sheet1', 'Sheet2', 'Sheet4', 'Sheet5']
for sheet in sheets:
d[sheet] = something
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rorance_ |
