Pandas DataFrame: nsmallest() function
DataFrame - nsmallest() function
The nsmallest() function is used to get the first n rows ordered by columns in ascending order.
This method is equivalent to df.sort_values(columns, ascending=True).head(n), but more performant.
Syntax:
DataFrame.nsmallest(self, n, columns, keep='first')
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
n | Number of items to retrieve.
|
int | Required |
columns | Column name or names to order by. | list or str | Required |
keep | Where there are duplicate values:
|
{‘first’, ‘last’, ‘all’} Default Value: ‘first’ |
Required |
Returns: DataFrame
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - nlargest() function
Next: DataFrame - stack() function
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework