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
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/dataframe/dataframe-nsmallest.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics