How to pivot a dataframe in Pandas? [duplicate]

You can use pivot_table:

pd.pivot_table(df, values="Value", index=['Country','Year'], columns="Indicator").reset_index()

this outputs:

 Indicator  Country     Year    1   2   3   4   5
 0          Angola      2005    6   13  10  11  5
 1          Angola      2006    3   2   7   3   6

Leave a Comment