Trying to replace certain strings with a binary value. I tried to find and replace but it only works for one value. I'd like to do it for multiple different labels. I'd like to replace dog and bat with 1 and cat and snail with 0 :
animal
0 cat
1 dog
2 snail
3 bat
4 deer
To:
animal
0 0
1 1
2 0
3 1
4 0
Here is my sample code:
cold=['cat','snail','deer']
df['animal'] = np.where(df['animal']=cold, '0', '1')