this is a seemingly simple ask but I can't seem to figure it out.
I have a dataframe like this
I just want the value of the 'cat' column to be 1 if the value in 'animal' is 'cat', and similarly for other values of the 'animal' column.
Here is the example dataset:
data = pd.DataFrame({'animal':['cat','cat', 'dog', 'fish'], 'cat':[0,0,0,0],'dog':[0,0,0,0],'fish':[0,0,0,0],'lion':[0,0,0,0]})
The catch is that I can't just simply binarize the values, because even though 'lion' is not in my column values, it still exists as a binary column. (The binary columns are defined already).
I found this from another post but can't seem to figure out how it works.
df.fillna('').apply(lambda x : x.index==x.name).astype(int).replace(0,"")
My actual dataset has ~100 binary columns to loop through.
Any help is appreciated, thank you!
