1

I want to convert the name of last three columns into a new column called 'medal' and create a new column called 'no of medals' which is the corresponding value according to different medals

I know how to convert rows to columns by using pivot table, but no idea about how to do inversely

and what if there is a 'na' in gold/silver/...columns? raw data

goal

lidito
  • 11
  • 2
  • Try df.melt(id_vars=['Year', 'Country'], var_name= 'medals', value_name='No of medals') – Vaishali Jun 18 '19 at 20:45
  • could you see my edited raw data and goal? I was thinking about melt but the outcome is not what I want, there's no duplicate in 'country' column – lidito Jun 18 '19 at 21:02
  • The data is the same as earlier, only as an image. People can not copy data from an image and hence it is recommended that you paste the data. Did you try the code I posted earlier? – Vaishali Jun 18 '19 at 23:31
  • yup but not the expected output..can I use left_join? – lidito Jun 19 '19 at 02:53

0 Answers0