The first code works, the second code block gives no Error but doesn't give the result I expected.
First code creates a new column ['Type']. Names of equal stores but with different names are binned in column['Type']. So: shop name A and Shop name B, are in column ['Naam']. The script labels both as 'Supermarket'in column ['Type']. So far so good.
The second block of code is supposed to lable every store / shop etc. that is not named in the Namendict.test dictionary. I want these not recognised shop / stores etc. labeld as ['Diversen']. Hope someone has a suggestion. Thanks!
1: working code:
from Namendict import test
for value in df['Naam']:
for i, (k,v) in enumerate(test.items()):
boolean_indexer = df['Naam'].str.contains(k)
df.loc[boolean_indexer, 'Type'] = (v)
2: supposed to work code ( no Error, but also no Diversen in column ['Type'], just NaN):
from Namendict import test
for value in df['Naam']:
for i, (k,v) in enumerate(test.items()):
boolean_indexer = df['Naam'].str.contains(k)
if True:
df.loc[boolean_indexer, 'Type'] = (v)
else:
df.loc[boolean_indexer, 'Type'] = ('Diversen.')
Many thanks. Janneman
if True:always evaluates toTrue, soDiversennever gets set. Think you might need to add some criteria to checking your condition.