'How to efficiently mix groups of columns in a pandas dataframe?

I have one dataframe in Python :

Winner_height Winner_rank Loser_height Loser_rank
183 15 185 32
195 42 178 12

And I would like to get a mixed database keeping the information about both players and a field that allows me to identify the winner (0 if it is player 1, 1 if it is player 2), as below :

Player_1_height Player_1_rank Player_2_height Player_2_rank Winner
183 15 185 32 0
178 12 195 42 1

Is there an efficient way to mix groups of columns with pandas, i.e. without drawing a random number for each row and creating a duplicate database?

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source