I have a dictionary with keys of 2 levels, and values at the second level being dataframes:
my_dict = {
'elem1':{'day1': pd.DataFrame(columns=['Col1', 'Col2']),
'day2': pd.DataFrame(columns=['Col1', 'Col2'])
},
'elem2':{'day1': pd.DataFrame(columns=['Col1', 'Col2']),
'day2': pd.DataFrame(columns=['Col1', 'Col2'])
'day3': pd.DataFrame(columns=['Col1', 'Col2'])
}
}
How do I convert this to a multi-index pandas dataframe of the form:
Col1 Col2
elem1 day1 ... ...
day2 ... ...
elem2 day1 ... ...
day2 ... ...
I have looked through these answers but am unable to stitch together a solution:
- Nested dictionary to multiindex dataframe where dictionary keys are column labels
- Nested Dictionary to MultiIndex pandas DataFrame (3 level)
- Construct pandas DataFrame from items in nested dictionary
- Convert list of dictionaries to a pandas DataFrame
- Nested dictionary to multiindex dataframe where dictionary keys are column labels