0

I have a pandas dataframe that has population information for different countries by year and I want to re-struture the way that it looks.

This is the original structure

Country | Year1 | Year2 | Year3 | Year4 | Year5  
  A       Pop1   Pop2    Pop3    Pop4    Pop5  
  B       Pop1   Pop2    Pop3    Pop4    Pop5  
  C       Pop1   Pop2    Pop3    Pop4    Pop5  

I want to change it to

| Country | Year | Population |
   A      Year1     Pop1
   A      Year2     Pop2
   A      Year3     Pop3
   A      Year4     Pop4
   A      Year5     Pop5
   B      Year1     Pop1
   B      Year2     Pop2
   B      Year3     Pop3
   B      Year4     Pop4
   B      Year5     Pop5
   C      Year1     Pop1
   C      Year2     Pop2
   C      Year3     Pop3
   C      Year4     Pop4
   C      Year5     Pop5

I do not know how to go about it and would really appreciate any help

0 Answers0