How to Dynamically Read Multiple Sheets from an Ex...
# questions
g
How to Dynamically Read Multiple Sheets from an Excel File in Kedro? Hi everyone! I'm currently working with Kedro and I need to load multiple sheets from an Excel file. The challenge is that I do not know the sheet names in advance, so I need to dynamically identify and load all available sheets. Could someone please guide me on how to achieve this in Kedro? What would be the best practice for integrating this with the Kedro data catalog? Thanks in advance for your help! Using right now: "constraints_{name_us}": type: pandas.ExcelDataset filepath: data/10_optimization_inputs/constraints_{name_us}.xlsx load_args: engine: openpyxl decimal: "." sheet_name: None (Sheet_name = None don't work)
d
what did you get? an error or a single dataframe?
g
A error, the sheet with name None its not in my excel file
d
so I’ve just tested with a project I happened to have open and it works as expected
does your YAML have the right whitespace?
Copy code
"constraints_{name_us}":
    type: pandas.ExcelDataset
    filepath: data/10_optimization_inputs/constraints_{name_us}.xlsx
    load_args:
       engine: openpyxl
       decimal: "."
       sheet_name: None
👍 1
g
Worksheet named None not found I am current using kedro 0.19.3
d
So is there any way you are passing
"None"
not
None
? so is there any reason why the
g
I tried the both 😕
d
Can you try
null
or
~
🥳 1
g
Yes, i will try 🙂
Work with null 😄
Thank you @datajoely ❤️
d
🙏
nasty issue that!
n
Or just leave the option? I think the default should be None anyway?
d
yeah I didn’t mention that technically this is valid:
Copy code
"constraints_{name_us}":
    type: pandas.ExcelDataset
    filepath: data/10_optimization_inputs/constraints_{name_us}.xlsx
    load_args:
       engine: openpyxl
       sheet_name: 
       decimal: "."
but it does feel like it breaks the
explicit is better than implicit
python mantra
n
https://pandas.pydata.org/docs/reference/api/pandas.read_excel.html Alright I am wrong the default is 0 which is the first sheet
d
oh you’re talking about the pandas arg
yeah technically an empty key is null in yaml
👍🏼 1
👍 1