MCPcopy
hub / github.com/pandas-dev/pandas / rank

Method rank

pandas/core/generic.py:9425–9582  ·  view source on GitHub ↗

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. Parameters ---------- axis : {0 or 'index', 1 or 'columns'}, default 0 Index to direct

(
        self,
        axis: Axis = 0,
        method: Literal["average", "min", "max", "first", "dense"] = "average",
        numeric_only: bool = False,
        na_option: Literal["keep", "top", "bottom"] = "keep",
        ascending: bool = True,
        pct: bool = False,
    )

Source from the content-addressed store, hash-verified

9423
9424 @final
9425 def rank(
9426 self,
9427 axis: Axis = 0,
9428 method: Literal["average", "min", "max", "first", "dense"] = "average",
9429 numeric_only: bool = False,
9430 na_option: Literal["keep", "top", "bottom"] = "keep",
9431 ascending: bool = True,
9432 pct: bool = False,
9433 ) -> Self:
9434 """
9435 Compute numerical data ranks (1 through n) along axis.
9436
9437 By default, equal values are assigned a rank that is the average of the
9438 ranks of those values.
9439
9440 Parameters
9441 ----------
9442 axis : {0 or 'index', 1 or 'columns'}, default 0
9443 Index to direct ranking.
9444 For `Series` this parameter is unused and defaults to 0.
9445 method : {'average', 'min', 'max', 'first', 'dense'}, default 'average'
9446 How to rank the group of records that have the same value (i.e. ties):
9447
9448 * average: average rank of the group
9449 * min: lowest rank in the group
9450 * max: highest rank in the group
9451 * first: ranks assigned in order they appear in the array
9452 * dense: like 'min', but rank always increases by 1 between groups.
9453
9454 numeric_only : bool, default False
9455 For DataFrame objects, rank only numeric columns if set to True.
9456
9457 .. versionchanged:: 2.0.0
9458 The default value of ``numeric_only`` is now ``False``.
9459
9460 na_option : {'keep', 'top', 'bottom'}, default 'keep'
9461 How to rank NaN values:
9462
9463 * keep: assign NaN rank to NaN values
9464 * top: assign lowest rank to NaN values
9465 * bottom: assign highest rank to NaN values
9466
9467 ascending : bool, default True
9468 Whether or not the elements should be ranked in ascending order.
9469 pct : bool, default False
9470 Whether or not to display the returned rankings in percentile
9471 form.
9472
9473 Returns
9474 -------
9475 same type as caller
9476 Return a Series or DataFrame with data ranks as values.
9477
9478 See Also
9479 --------
9480 core.groupby.DataFrameGroupBy.rank : Rank of values within each group.
9481 core.groupby.SeriesGroupBy.rank : Rank of values within each group.
9482

Callers 15

time_rankMethod · 0.45
time_rankMethod · 0.45
time_average_oldMethod · 0.45
time_rank_stringMethod · 0.45
time_rank_string_catMethod · 0.45
time_rank_intMethod · 0.45
time_rank_int_catMethod · 0.45
time_rankMethod · 0.45
time_rankMethod · 0.45
time_rank_tiesMethod · 0.45

Calls 3

_get_axis_numberMethod · 0.95
_get_numeric_dataMethod · 0.95
is_numeric_dtypeFunction · 0.90

Tested by 15

test_basicMethod · 0.36
test_uint64_overflowMethod · 0.36
test_rank_tiny_valuesMethod · 0.36
test_too_many_ndimsMethod · 0.36
test_rankFunction · 0.36
test_rankFunction · 0.36
test_rankMethod · 0.36
test_rank_categoricalMethod · 0.36
test_rank_signatureMethod · 0.36
test_rank_tie_methodsMethod · 0.36