I'm using pandas' nsmallest
in order to find n rows with smallest values in a specific column, and If I understand correctly it returns a data frame object;
How can I remove those rows from the data frame?
pandas' drop
gets only rows indexes, not a data frame
Asked
Active
Viewed 1,083 times
2
-
Hello, we need a [minimal complete and reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) to be able to help. You can refer [how to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and create one in your question body – anky Apr 22 '21 at 15:42
1 Answers
1
Drop 3 smallest values of a series
(or a specific column):
>>> sr
0 22 # <- drop
1 45 # <- drop
2 61
3 65
4 74
5 78
6 58
7 73
8 13 # <- drop
9 91
dtype: int64
>>> sr.nsmallest(3)
8 13
0 22
1 45
dtype: int64
>>> sr.drop(sr.nsmallest(3).index)
2 61
3 65
4 74
5 78
6 58
7 73
9 91
dtype: int64

Corralien
- 109,409
- 8
- 28
- 52