Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Can i combine contain and startswith in order to match two columns from one dataframe to another's master column?

$
0
0

Master dataframe filled with a specific match's players and statistics.34 columns and variable number of rows.
Column "Player" has full names

PlayerGoalsAssists
Dominic Calvert-Lewin11
Beto20
Jarrad Branthwaite01
Jack Harrison00

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 NameLast NameCause
DCalvert-LewinFoul
BetoTime Wasting
JackHarrison

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:

PlayerCause
Dominic Calvert-LewinFoul
BetoTime 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('')

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>