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:
JavaScript
x
2
1
final = trainData_Ceros.drop(rus1,axis=0)
2
But the following error appears:
JavaScript
1
2
1
KeyError: "['id' 'text' 'label'] not found in axis"
2
Can anyone help me please?
Advertisement
Answer
You can use this slicing
JavaScript
1
2
1
final[~final.id.isin(rus1)]
2
And if you want to use drop then you can do this
JavaScript
1
2
1
final.drop(final[final.id.isin(rus1)].index)
2