简体   繁体   中英

How to remove a group of specific rows from a dataframe?

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM