Reputation: 81
I have a 121 rows × 20 columns dataframe
I want to delete the rows from the picture below
I had tried :
sv.drop(sv[(sv['Visit_Duration'] == 'Never') & (sv['Visit_Plan'] == 'never')].index,axis=1)
SO I tried
sv.drop(labels=[44,67,107,108,112],axis=0)
BUT the result are the same as the original dataframe with 121 rows x 20 columns
Upvotes: 0
Views: 1020
Reputation:
Why even delete them? Just filter them out. You want to keep the rows that don't satisfy the conditions you specified here, so you want the negation of A&B
, which is ~A|~B
:
sv = sv[(sv['Visit_Duration'] != 'Never') | (sv['Visit_Plan'] != 'never')]
or equivalently (~(A&B)
),
sv = sv[~((sv['Visit_Duration'] == 'Never') & (sv['Visit_Plan'] == 'never'))]
Upvotes: 3
Reputation: 242
You're almost there, you forget to reassign the result to the dataframe variable.
Try instead:
sv = sv.drop(labels=[44,67,107,108,112],axis=0)
Or you can also use the inplace=True
argument for the drop
function.
sv.drop(labels=[44,67,107,108,112], axis=0, inplace=True)
Upvotes: 3