Python pandas editing multiple rows

Hi here’s my database

and I want to change Player rows so I’m left only with Player first name and surname and get rid of initials. For example Instead of Nikola Jokićjokicni01 I need Nikola Jokić only.


You can use str.split() and grab the first part of the list:

import pandas as pd

df['Player'] =df['Player'].str.split('\').str[0]

Or with pd.assign

df = df.assign(Player = df.Player.str.split('\').str[0])

Initial DF:

                            Player Pos
0          Nikola Jokicjokicni01   C
1  Giannis Antetokounmpoantegi01  PF
2         Stephen Currycurryst01  PG

Resulting DF:

                  Player Pos
0           Nikola Jokic   C
1  Giannis Antetokounmpo  PF
2          Stephen Curry  PG