Q:

Pandas: Looping through a list of strings in a column & create a new column with string

Goal: I would like to search through a column called "Profile Name" in my DF and whether part of the name contains a certain market. For example, if the "Profile Name" (XX - France - AM) contains "France", I would like to add the string "France" to a new column called "Markets" in the DF. Ideally, I want to use a loop to go through 5 different markets and apply the same logic (i.e. if "Profile Name" contains Italy, add Italy to "Markets". 
I've tried many different versions to do this but this seems to be the closest:
markets = ['France','Spain','UK','Germany','Italy']
for name in markets:
    if df[df['Profile Name'].str.contains(name, na=False) == True]:
       df['Market'] = name

It gives me this error: ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Anyone has a suggestion on how I can do this best? Thank you!

A:

You can do all in one line:
df['Market'] = df['Profile Name'].str.extract(f'({"|".join(markets)})')

Update: run time comparison (len(df) = 8000).
%%timeit -n 100
df['Market'] = df['Profile Name'].str.extract(f'({"|".join(markets)})')
# 8.46 ms ± 151 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

%%timeit -n 100
for name in markets:
    df.loc[df['Profile Name'].str.contains(name, na=False, regex=False), 'Market'] = name
# 16.7 ms ± 200 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

