I have a dataframe that contains values for countries and years:
country year value
US 2000 20
JP 2000 10
AU 2000 5
US 2001 22
JP 2001 12
AU 2001 6
US 2002 23
JP 2002 14
AU 2002 8
I want to calculate the percent change for each country between years, so I group by countries and iterate per group:
grouped=df.groupBy('country')
for group in grouped:
group['pct']=group['value'].pct_change(periods=1)*100
How can I create a new dataframe from 'grouped' containing my new column pct?