I have a World Indicator dataset that has this format
country year indicatorName value
USA 1970 Agricultural Land ...
USA 1970 Crop production ...
...
USA 2000 Agricultural Land ...
USA 2000 Crop production ...
...
Mexico 1970 Agricultural Land ...
Mexico 1970 Crop production ...
...
Mexico 2000 Agricultural Land ...
Mexico 2000 Crop production ...
There are indicators here that I did not include, but these two are what I'm interested in. I want to divide the corresponding value of Crop production to Agricultural Land per country per year. Let's name the result crop_prod_density.
I do not know how to proceed from
df.groupby(['country', 'year'])
How to do it from here to result the following outputs:
- Add new row indicator
country year indicatorName value
USA 1970 Agricultural Land ...
USA 1970 Crop production ...
USA 1970 crop_prod_density ...
- Add new column with same values for all rows for grouped (country, year)
country year indicatorName value crop_prod_density
USA 1970 Agricultural Land ... us_value_1970
USA 1970 Crop production ... us_value_1970
...
Mexico 2000 Agricultural Land ... mx_value_2000
Mexico 2000 Crop production ... mx_value_2000
- New dataframe with only this column for values
country year crop_prod_density
USA 1970 us_value_1970
...
USA 2000 us_value_2000
...
Mexico 1970 mx_value_1970
...
Mexico 2000 mx_value_2000