I believe this is the same issue as #6322 .
The code below returns the error: IndexError: cannot do a non-empty take from an empty axes.
import pandas as pd
import numpy as np
import random
import string
# Create 12 random strings 3 char long
rndm_strgs = [''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(3)) for i in range(12)]
rndm_strgs[0] = None
rndm_strgs[5] = None
# Make Dataframe
df = pd.DataFrame({'A' : list('pandasisgood'),
'B' : np.nan,
'C' : rndm_strgs,
'D' : np.random.rand(12)})
# Set an Index -> Columns have Nans
df_w_idx = df.set_index(['A','B','C'])
df_w_idx.reset_index()
To get the result I wanted:
for clmNm in df_w_idx.index.names:
print(clmNm)
df_w_idx[clmNm] = df_w_idx.index.get_level_values(clmNm)
df_w_idx = df_w_idx.reset_index(drop=True).copy()
df_w_idx
Comment From: jreback
pls just put this example on the duplicated issue instead