df.melt() df.pivot()
df.melt(),df.pivot() 互为逆转函数
In [23]:
df=pd.DataFrame({'A':['a','b','c'],
'B':[1,3,5],
'C':[2,4,6]})
In [24]:
df
Out[24]:
In [29]:
melted=df.melt('A')
melted
Out[29]:
In [32]:
reshaped=melted.pivot(index='A',columns='variable')
reshaped
Out[32]:
In [33]:
reshaped.reset_index()
Out[33]: