This is the dataframe I want to iterate through. The index is set for both countries and year.
ISO_code gini ECONOMIC FREEDOM rank quartile 1a_government_consumption
countries year
Argentina 1980 ARG 40.8 4.25 80.0 4.0 6.911765
1995 ARG 48.9 6.95 37.0 2.0 8.058824
2000 ARG 51.1 7.34 37.0 2.0 6.877627
2001 ARG 53.3 6.84 56.0 2.0 6.752473
2002 ARG 53.8 6.28 79.0 3.0 6.905961
2003 ARG 50.7 6.16 86.0 3.0 7.264992
Bolivia 1980 BOL 40.8 4.25 80.0 4.0 6.911765
1985 BOL 48.9 6.95 37.0 2.0 8.058824
1995 BOL 51.1 7.34 37.0 2.0 6.877627
2000 BOL 53.3 6.84 56.0 2.0 6.752473
2001 BOL 53.8 6.28 79.0 3.0 6.905961
2002 BOL 50.7 6.16 86.0 3.0 7.264992
Chile 1985 CHI 40.8 4.25 80.0 4.0 6.911765
1990 CHI 48.9 6.95 37.0 2.0 8.058824
1995 CHI 51.1 7.34 37.0 2.0 6.877627
1999 CHI 53.3 6.84 56.0 2.0 6.752473
2002 CHI 53.8 6.28 79.0 3.0 6.905961
2003 CHI 50.7 6.16 86.0 3.0 7.264992
I would like to create a for loop that returns a dataframe like this one:
countries change gini change ef
Argentina + +
Bolivia - +
Chile - -
countriesis simply the columns with the country names from the previous dataframe.change ginishould be the percentage difference between the last value of theginicolumn for each country and the most recent one. If the percentage increase is positive, then it should show a+; if it is negativa then it should show a-.change effollows the same logic as thechange giniin the new dataframe, with the only difference that the values used for calculating the percentage change come from theECONOMIC FREEDOMcolumn in the original dataframe.