py_research.ranking module#

Functions for ranking entities by multiple criteria.

create_rank_series(rank_by, rank_mode='descending', exclude=None, name='rank')[source]#

Create a series of ranks given a series of values to rank by.

Parameters:
  • rank_by (Series | list[Series] | DataFrame) – Series of values to rank by.

  • rank_mode (Literal['ascending', 'descending']) – Whether to rank ascending or descending.

  • exclude (Series | None) – Values to exclude from ranking.

  • name (str) – Name of the resulting series.

Returns:

Series of ranks.

Return type:

Series

create_ranking_filter(rank_by, cutoff_rank, sort_order='descending', rank_only=None, show_only=None, show_always=None, count_always_shown=False)[source]#

Create a filter based on ranking.

Parameters:
  • rank_by (Series) – Series of values to rank by.

  • cutoff_rank (int) – Cutoff rank for the filter.

  • sort_order (Literal['ascending', 'descending']) – Whether to rank ascending or descending.

  • rank_only (Series | None) – Only rank the given values.

  • show_only (Series | None) – Only show the given values.

  • show_always (Series | None) – Always show the given values.

  • count_always_shown (bool) – Whether to count the values in show_always as ranks.

Returns:

Boolean series representing the filter. The series name contains a description of the filter.

Return type:

Series