pandas filter and change value 1

pandas filter and change value

df.loc[df['dollars_spent'] > 0, 'purchase'] = 1

Here is what the above code is Doing:
1. Create a new column called ‘purchase’
2. Set the value of ‘purchase’ to 0 for all rows
3. Set the value of ‘purchase’ to 1 for all rows where ‘dollars_spent’ is greater than 0

Similar Posts