Pandas DataFrame: rank() function
DataFrame - rank() function
The rank() function is used to compute numerical data ranks (1 through n) along axis.
By default, equal values are assigned a rank that is the average of the ranks of those values.
Syntax:
DataFrame.rank(self, axis=0, method='average', numeric_only=None, na_option='keep', ascending=True, pct=False)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
axis | Index to direct ranking. | {0 or ‘index’, 1 or ‘columns’} Default Value: 0 |
Required |
method | How to rank the group of records that have the same value (i.e. ties):
|
{‘average’, ‘min’, ‘max’, ‘first’, ‘dense’} Default Value: ‘average’ |
Required |
numeric_only | For DataFrame objects, rank only numeric columns if set to True. | bool |
Optional |
na_option | How to rank NaN values:
|
{‘keep’, ‘top’, ‘bottom’} Default Value: ‘keep’ |
Required |
ascending | Whether or not the elements should be ranked in ascending order. | bool Default Value: True |
Required |
pct | Whether or not to display the returned rankings in percentile form. | bool Default Value: False |
Required |
Returns: same type as caller
Return a Series or DataFrame with data ranks as values.
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - quantile() function
Next: DataFrame - round() 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://w3resource.com/pandas/dataframe/dataframe-rank.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics