Reputation: 1537
How do I pivot and group by country this dataframe and use YEAR as column
pandas.DataFrame = (data = {'COUNTRY': ['USA', 'USA', 'UK', 'UK'],
'YEAR': [1999, 2000, 1999, 2000],
'VALUE': [99, 111, 88, 100]} )
Such as I get this output:
Upvotes: 1
Views: 37
Reputation: 195428
print(df.pivot(index="COUNTRY", columns="YEAR", values="VALUE").reset_index())
Prints:
YEAR COUNTRY 1999 2000
0 UK 88 100
1 USA 99 111
Upvotes: 2