'How to prepare the pandas dataframe I have to make animated bar plots using bar_chart_race?

I have a pandas dataframe like this:

enter image description here

After I transpose it, it becomes this:

enter image description here .

What I want is to rename 'Country Name' to 'Years' and use it as an index column, and names of the countries as separate columns and use those columns as values for the bar plot. This, I believe, is a prerequisite for making animated bar plots using bar_chart_race. But renaming the column using pd.rename does not work. I am also confused whether transposing the dataframe was the best move here. I don't quite understand how pd.melt() or pd. pivot() will help me. Any suggestions would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source