Master dataframe filled with a specific match's players and statistics.
34 columns and variable number of rows.
Column "Player" has full names
| Player | Goals | Assists |
|---|---|---|
| Dominic Calvert-Lewin | 1 | 1 |
| Beto | 2 | 0 |
| Jarrad Branthwaite | 0 | 1 |
| Jack Harrison | 0 | 0 |
Snippet dataframe automatically created, displays only players with a referee note (Yelllow cards, Red Cards). Consists of 3 columns. The problem is that First Name is either a full name, initial letter or blank.
| First Name | Last Name | Cause |
|---|---|---|
| D | Calvert-Lewin | Foul |
| Beto | Time Wasting | |
| Jack | Harrison |
What i want to achieve:
Match "First Name" probably using startswith along "Last Name" using contains, with Player in master df.
If both colums match add a column to Snippet df with fullnames.
Expected dataframe:
| Player | Cause |
|---|---|
| Dominic Calvert-Lewin | Foul |
| Beto | Time Wasting |
| Jack Harrison |
So far i only had one to one matching:
pat1 = '('+'|'.join(Snippet['Last Name'])+')'
Master["Yellow"] = Master['Player'].str.extract(pat1)[0].map(Snippet.set_index('Last Name')['Cause'].to_dict()).fillna('')