I have a dataframe in the form {'country','year','value'}. I want to move it in the form of:
country.........1961....1962....1963
countryname.....value...value...value.
Therefore I have used df1=df.pivot(index='country',column='year',value='value')
the output comes in the form
year..........1961....1962....1963
country
countryname...value...value...value
Now I would like to replace the long official names used for some countries and insert a shorter name (i.e. Islamic Republic of Iran --> Iran). I have a second dataframe that contains these couples and am trying to get the index labels with
for i in df1.loc[:,['country']]
but i get back the Key error: 'country'. I tried using 'year' instead of 'country' but with the same result.
How do I reference the index after pivoting?
Your help would be greatly appreciated.