Flattening Multi index dataframe
def tidify(df):
if isinstance(df.index, pd.core.index.MultiIndex):
df = df.copy()
new_colnames = []
for v in df.columns:
new_colnames.append('_'.join(v))
df.columns = new_colnames
df.reset_index(inplace=True)
return df
else:
df = df.copy()
df.reset_index(inplace=True)
return df