0

I have a data frame that is currently set up with Country Name, Indicator Name, and the corresponding Years as columns. I'd like to pivot the data frame so the Indicators are the column variables, while grouping by the Country Name's and their corresponding years.

I have tried:

df.pivot(index = 'Country Name', columns = 'Indicator Name', values = df.columns[2:])

However, this uses each year as a column with each indicator under it. Any ideas on how to fix this?

Country Data Frame:

Country Data Frame

Henry Ecker
  • 31,792
  • 14
  • 29
  • 50
  • 1
    Please [do not post images](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question) of your data. You can include [code that creates a dataframe or the output of `print(df)`](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) (or of a few rows and columns that allow to reproduce the example) – Cimbali Jun 29 '21 at 12:12

0 Answers0