I created a dictonary with Key and Value and want to write a Loop in a Loop:
for key,val in dict.items():
def contains(x, y):
result = np.nan
for i in x:
if i.lower() in y.lower():
result = key
return result
df['Test'] = df['Countrylist'].apply(lambda x: contains([val], x))
So I want to check if the Value in the Dictonary is in the Countrylist and if yes, then give the new Column Test the Value of the Key in the Dictonary.
But my code doesnt work...
Expected Output:
Countrylist Bla1 Bla2 Test
Germany 12 12 "Here should be the Key of the Dic"