I have a column in a dataframe that I want to split into two columns. The values in the column are strings with a players' name followed by their position. Because players have different numbers of names, this becomes a bigger issue.
For example:
- 1 name:
Jorginho Defensive Midfield - 2 names:
Heung-min Son Left Winger - 3 names:
Bilal El Khannouss Attacking Midfield
The desired output would be:
Player Position
Jorginho Defensive Midfield
Heung-min Son Left Winger
Bilal El Khannouss Attacking Midfield
I believe this can be done by listing the player positions, however I don't know how to approach that problem. I tried separating using split() with a space character as the delimiter, but that doesn't work unfortunately.
import pandas as pd
df = pd.DataFrame({'Player': ['Richarlison Centre-Forward',
'Heung-min Son Left Winger',
'Harry Wilson Right Winger',
'Bilal El Khannouss Attacking Midfield',
'Eduardo Camavinga Central Midfield',
'Jorginho Defensive Midfield',
'Lewis Patterson Centre-Back',
'Layvin Kurzawa Left-Back',
'Kyle Walker Right-Back',
'Jordan Pickford Goalkeeper']})
positions = ['Centre-Forward', 'Left Winger', 'Right Winger',
'Attacking Midfield', 'Central Midfield', 'Defensive Midfield',
'Centre-Back', 'Left-Back', 'Right-Back', 'Goalkeeper']
Is this possible to do?