cvr.tables.CastVoteRecord_tables

class cvr.tables.CastVoteRecord_tables

Bases: object

Extra methods for CastVoteRecord class.

__init__()

Methods

__init__()

get_annotated_cvr_table()

get_crossover_tables()

Table describing co-ranking patterns between candidates.

get_cvr_table([table_format, disaggregate])

Return the cvr as pandas dataframe.

get_rank_usage_table()

Table describing rank usage patterns.

get_crossover_tables() Tuple[DataFrame]

Table describing co-ranking patterns between candidates. For each subset of ballots organized by first choice candidate, one in each row of the table, the frequency with which all candidates appear in the top 3 ranks of ballots in that subset is calculated. For this table, ballots are used without any contest rules applied.

Returns:

Tuple of two pandas dataframes. The first contains counts, the second percentages.

Return type:

Tuple[pd.DataFrame]

get_cvr_table(table_format: str = 'rank', disaggregate: bool = True) DataFrame

Return the cvr as pandas dataframe. Two format options are available ‘rank’ or ‘candidate’.

Parameters:
  • table_format (str, optional) – Two choices for the format of CVR table, “rank” or “candidate”. One ballot per row. Rank format uses rank number labels as column headers with candidate names in row cells. Candidate format puts candidate names as column headers with rank position placed in row cells. Defaults to “rank”

  • disaggregate (bool, optional) – If True, the interally aggregated CVR is disaggregated back to contain the same number of ballots as when it was parsed, defaults to True.

Raises:

RuntimeError – raised if an invalid table_format is passed as an argument.

Returns:

Dataframe containing CVR.

Return type:

pd.DataFrame

get_rank_usage_table() DataFrame

Table describing rank usage patterns. Mean rankings used and distribution of valid rankings used is provided for all ballots (excluding undervotes and ballots starting with overvotes) as well as ballots separated by first choice candidate. Ballots starting with overvotes are excluded because of the inability to assign them to a first choice candidate category. For this table, ballots are used without any contest rules applied. Skipped ranks, overvotes, and duplicate rankings are not counted valid rankings.

Returns:

Rank usage dataframe

Return type:

pd.DataFrame