I have a pandas dataframe as follows.
name x1 x2
0 a 5 5
1 b 8 6
2 e 3 8
I also have a list of namesas follows.
lst = [a, e]
I want to add a column named as final_values to my current dataframe where;
- if the
nameis inlstthe column value should be1 - else
0
So, my updated dataframe should look as follows.
name x1 x2 final_values
0 a 5 5 1
1 b 8 6 0
2 e 3 8 1
Is there any easy way of doing this in pandas?
I am happy to provide more details if needed.
df.name.isin(lst).astype(int)