This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from types import Union # in Python 3.10 in not needed since we can define the Union as "type | type" | |
def multiindex2dict(p: Union[pd.MultiIndex, dict]) -> dict: | |
""" | |
Converts a pandas Multiindex to a nested dict | |
:parm p: As this is a recursive function, initially p is a pd.MultiIndex, but after the first iteration it takes | |
the internal_dict value, so it becomes to a dictionary | |
""" |