0

I have a data frame which is of the following format: enter image description here

I need the data frame with separate columns for 'Rank' and 'Percentage'. The final data should be of the following format: enter image description here

Akankshya
  • 27
  • 3
  • 1
    please post data as text. no images. thanks! – Naveed Jul 07 '22 at 16:14
  • Something like this? https://stackoverflow.com/questions/46375147/create-new-columns-from-unique-row-values-in-a-pandas-dataframe – Bijay Regmi Jul 07 '22 at 16:15
  • Use: `df.pivot(['Name', 'ID', 'Year'], columns='Variable', values='Value')` – Mayank Porwal Jul 07 '22 at 16:19
  • @MayankPorwal I tried doing this. I am getting a Keyerror '0'. – Akankshya Jul 07 '22 at 16:48
  • @BijayRegmi I tried both the methods mentioned in the solution given in the link you mentioned. set_index won't work in my case as there is duplicate data and the first solution involving pivot_table is throwing a KeyError '0' – Akankshya Jul 07 '22 at 16:51

0 Answers0