Home > OS >  How to remove a group of specific rows from a dataframe?
How to remove a group of specific rows from a dataframe?

Time:06-04

I have a dataframe with 7581 rows and 3 columns (id,text,label). And I have a subgroup of this dataframe of 794 rows.

What I need to do is to remove that subgroup of 794 rows (same labels) from the big dataframe of 7581.

This is how the subgroup looks like: Photo

I have tried to do this:

final = trainData_Ceros.drop(rus1,axis=0)

But the following error appears:

KeyError: "['id' 'text' 'label'] not found in axis"

Can anyone help me please?

CodePudding user response:

You can use this slicing

final[~final.id.isin(rus1)]

And if you want to use drop then you can do this

final.drop(final[final.id.isin(rus1)].index)
  • Related