I have a DataFrame (e.g., df_p
) which has already converted into a pivot table:
import pandas as pd
df = pd.DataFrame({'start_year':[2000, 2001, 2002],
'end_year':[2010, 2011, 2012],
'price':[1.0, 2.0, 3.0]})
# end_year price start_year
# 0 2010 1.0 2000
# 1 2011 2.0 2001
# 2 2012 3.0 2002
df_p = df.pivot('start_year', 'end_year', 'price')
# end_year 2010 2011 2012
# start_year
# 2000 1.0 NaN NaN
# 2001 NaN 2.0 NaN
# 2002 NaN NaN 3.0
How should I convert df_p
back to df
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…