Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading