Pandas Hierarchical Indexing

Pandas Hierarchical Indexing

Multiply Indexed Series

Pandas MultiIndex

Pandas MultiIndex

MultiIndex as Extra Dimension

MultiIndex as Extra Dimension

MultiIndex Operations

Creating MultiIndex Objects

MultiIndex Constructors

MultiIndex Level Names

Example: MultiIndex Columns

>>> index = pd.MultiIndex.from_product(
...     [[2018, 2019], [1,2]],
...     names=['year', 'visit'])
>>> columns = pd.MultiIndex.from_product(
...     [['Alice', 'Bob'],['test2','test1']],
...     names=['name','type'])
>>> health_data = pd.DataFrame(data,
...     index=index, columns=columns)
>>> health_data
name           Alice                 Bob          
type           test2     test1     test2     test1
year visit                                        
2018 1     -0.856664 -1.819912  0.864426  0.127241
     2      0.482796  0.824717  0.605018 -0.613014
2019 1     -1.052893 -0.550636 -0.510358  0.923357
     2      0.427429  0.114259  0.835249  1.095828

Example: MultiIndex Columns