I have a dataset with various columns as below:
discount tax total subtotal productid
3.98 1.06 21.06 20 3232
3.98 1.06 21.06 20 3232
3.98 6 106 100 3498
3.98 6 106 100 3743
3.98 6 106 100 3350
3.98 6 106 100 3370
46.49 3.36 66.84 63 695
Now, I need to add a new column Class and assign it the value of 0
or 1
on the base of the following conditions:
if:
discount > 20%
no tax
total > 100
then the Class will 1
otherwise it should be 0
I have done it with a single condition but I don't how can I accomplish it under multiple conditions.
Here's wIat i have tried:
df_full['Class'] = df_full['amount'].map(lambda x: 1 if x > 100 else 0)
I have taken a look at all other similar questions but couldn't find any solution for my problem.I have tried all of the above-mentioned posts but stuck on this error:
TypeError: '>' not supported between instances of 'str' and 'int'
Here's in the case of first posted answer, i have tried it as:
df_full['class'] = np.where( ( (df_full['discount'] > 20) & (df_full['tax'] == 0 ) & (df_full['total'] > 100) & df_full['productdiscount'] ) , 1, 0)