0

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.

  • Please [don't post images of code/data/error messages](https://meta.stackoverflow.com/a/285557/8881141). Post the formatted text directly here on SO. See also [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Mr. T Mar 24 '22 at 07:06

0 Answers0