I have a column with text. This text can contain the name of countries. I want to have a list of all countries mentioned in a column in the same row as the text. I already have a series with the countries I want to extract.
SomeText | ... | .... | CountryInText
Something Canada | | |
RUSSIAAreACountry | | |
Mexicoand Brazil is South of USA
SomeText | ... | .... | CountryInText
Something Canada | | | Canada
RUSSIAAreACountry | | | Russia
Mexicoand Brazil is South of USA | | | Mexico, Brazil, USA
I've tried with
pd.Series(df['SomeText'].str.findall(f"({'|'.join(countryname['CommonName'])})"))
However, this gives me a list of object that I can't match back to the original dataframe. The countryname['CommonName'] is a series of country names.
Can anyone help me ?
Thanks in advance