I have a df (dfA) with the life expectancy at birth and gdp per year of 6 countries. with the following structure:
country year expectancy gdp difference
chile 2000 60 1bn NA
chile 2001 63 1.5bn 0.5bn
chile 2002 65 2.5bn 0.5bn
chile 2003 68 3.5bn 1.0bn
.
.
.
chile 2015 80 10bn 10bn
Each row represents the data (gdp, expectancy, etc) for a country per year, spanning from the year 2000 to 2015 and with 6 countries.
I have created a new dataframe to store important overall variables per country, such as GDP delta (GDP in 2015 minus GDP in 2000) per country. The new df (dfB) looks like this:
country startEndDelta (dummydata)
Chile x
China y
Germany z
Mexico a
USA b
Zimbabwe c
What I want to do is add a new column to my newdf that shows which year had the greatest increase in GDP for each country.
I was already able to calcualte the year but I first had to create another dataframe with records from only one country. Here I do it the way I metioned before.
The way I wish to do this would be something similar to:
dfB['biggestDeltaYear'] = ?year with the biggest increase in GDP?
Where this single line of code populates every row in dfB for my new column 'biggestDeltaYear'.
What are my options?
Thank you very much