I have a small dataframe, df, that I am testing some code on, before using the code on a larger set
id make price
21 Boss 300
22 LG 400
23 EE 500
24 Orange 750
I am trying to find a way of determining if a value already exists in a column before inserting that value.
This code snippet works
newval = 'EE'
for val in df.make:
if val == newval:
print(val)
else:
print('not the val')
However this snippet, that should more cleanly identify if a value already exists in a specific column of the dataframe, does not appear to work in that it prints 'Available to add', despite 'EE' already existing in the 'make' column.
newval = 'EE'
if newval in df.make:
print('In there already')
else:
print('Available to add')
If I test for true or false
exists = 'EE' in df.make
print(exists)
I get False, despite the fact that 'EE' is clearly already in the 'make' column
Why am I not getting True and 'Available to add'
I am sure that I am missing something very simple but cannot see it. Can someone point me in the right direction