I have following dataframe df in pandas
item purchase_date purchase_qty purchase_price other_adjustments sold
0 0040030 2022-01 0 0.00 0 0.0
1 0050064 2022-01 0 0.00 -5 854.0
2 0050066 2022-01 0 0.00 2979 0.0
3 0050202 2022-01 0 0.00 14673 1320.0
4 0050204 2022-01 0 0.00 2538 0.0
I need to delete rows if all purchase_qty,other_adjustments and sold is 0.
I tried this
test_df = df[(df['purchase_qty'] != 0) & (df['other_adjustments'] != 0) & (df['sold'] != 0)]
This code delete all purchase_qty where it’s value is 0 but what I want is to check those 3 column and if all three are 0 then delete. Please help me
>Solution :
You need use or condition
test_df = df[(df['purchase_qty'] != 0) | (df['other_adjustments'] != 0) | (df['sold'] != 0)]
Or you can do an inverse operation
test_df = df[~((df['purchase_qty'] == 0) & (df['other_adjustments'] == 0) & (df['sold'] == 0))]