Home > Net >  How do I sort values by name that have a matching element?
How do I sort values by name that have a matching element?

Time:12-05

In this DataFrame, the teams need to stay in the same position, but I want to sort the players within each team.

                 Team                Player  Apps
0    Newcastle_United             Joelinton   5.0
1    Newcastle_United   Allan Saint-Maximin   5.0
2    Newcastle_United         Callum Wilson   5.0
3    Newcastle_United      Jamaal Lascelles   5.0
4    Newcastle_United         Jeff Hendrick   2.0
..                ...                   ...   ...
471           Arsenal            Pablo Marí   2.0
472           Arsenal  Albert Sambi Lokonga   5.0
473           Arsenal       Folarin Balogun   2.0
474           Arsenal          Nuno Tavares   5.0
475           Arsenal                 Total   NaN

In this case, the output should look like:

                 Team                 Player  Apps
0    Newcastle_United    Allan Saint-Maximin  5.0
1    Newcastle_United          Callum Wilson  5.0
etc

I can't sort by 'Team', 'Player', though, because that would rearrange the order of the teams.

I feel like this should have a pretty simple solution, but I'm stumped. Thank you in advance!

CodePudding user response:

A more convenient way is to use enter image description here

  • Related