Skip to content
Advertisement

To add new columns that identify the value position by each column with loop

I have Dataframe:

JavaScript

And I’m trying to add new columns that identify the team position by each column

I wanna get this:

JavaScript

I tried to do something similar with the following code, but to no avail. The result is a list

JavaScript

Advertisement

Answer

Use DataFrame.rank with DataFrame.add_prefix and add new DataFrame to original DataFrame by DataFrame.join:

JavaScript

Another idea with for loop and f-strings for new columns names:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement