I would like to create an empty DataFrame with a MultiIndex before assigning rows to it. I already found that empty DataFrames
Another solution which is maybe a little simpler is to use the function set_index
:
>>> import pandas as pd
>>> df = pd.DataFrame(columns=['one', 'two', 'three', 'alpha', 'beta'])
>>> df = df.set_index(['one', 'two', 'three'])
>>> df
Empty DataFrame
Columns: [alpha, beta]
Index: []
>>> df.loc[('apple','banana','cherry'),:] = [0.1, 0.2]
>>> df
alpha beta
one two three
apple banana cherry 0.1 0.2