- 将 multindex的index转换为columns
df = pd.DataFrame(np.arange(12).reshape((4,3)), index=[['a','a','b','b'], [1,2,1,2]], columns=['green','blue','red'])
df.index.names=['key1','key2']
print(df)
df.reset_index(level=[0,1])
df.reset_index(level=['key1','key2'])
http://dougaoyang.github.io/2017/09/22/convert-pandas-index-in-dataframe-to-column.html
网友评论