this is simple question but i don't know why i cannot compare if corectly.
df:
A,B
1,marta
2,adam1
3,kama
4,mike
i want to print 'exist' if specific name exist in df
for example, i want to check if marta exist in df['B']
code:
string='www\marta2'
if df['B'].str.contains(string,regex=False).all()==True:
print('exist')
else:
print('not exist')
when i am using .bool() instead of all() i am receiving error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I am reveiving False on each line, why ? should i compare this type of string some how in different way?
EDIT:
I need to use IF statement because in my code instead of print my code need to assigh variables, normaly i would use different way.
If my string='marta' it works well but with additional string not
EDIT:
new code:
string='www\marta2'
if df['B'].str.rfind(string).any():
print('exist')
else:
print('not exist')
but it compares everything, so even if one letter is in column it will print 'exist'
'marta'does not contain'www\marta2'. This:string='mart'; print(df['B'].str.contains(string,regex=False).any())does printTrue...