pandas.Series.rank

pandas 3.1.1 · Series and accessors · method

Assign positions in sorted order and choose how to handle ties.

Call syntax

Series.rank(
    axis=0,
    method='average',
    numeric_only=False,
    na_option='keep',
    ascending=True,
    pct=False,
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
axis Optional
Positional or keyword
Default 0
{0 or 'index', 1 or 'columns'}

Choose which axis the operation acts on. The accepted axis labels depend on the receiver.

method Optional
Positional or keyword
Default 'average'
{'average', 'min', 'max', 'first', 'dense'}

Choose the algorithm used to calculate, align, or fill the result.

numeric_only Optional
Positional or keyword
Default False
bool

Restrict the calculation to columns pandas considers numeric where applicable.

na_option Optional
Positional or keyword
Default 'keep'
{'keep', 'top', 'bottom'}
ascending Optional
Positional or keyword
Default True
bool

Choose ascending or descending order. Some sorting methods take one flag per sort key.

pct Optional
Positional or keyword
Default False
bool

Express ranks or results as fractions where the API supports this option.

Returns

same type as caller