Skip to content

boolean_stats

boolean_stats ¤

BooleanStatistics ¤

BooleanStatistics(
    dataframe: DataFrame, time_column: str = "systime"
)

Bases: Base

Provides class methods to calculate statistics on a boolean column in a pandas DataFrame.

count_true classmethod ¤

count_true(
    dataframe: DataFrame, value_column: str = "value_bool"
) -> int

Returns the count of True values in the boolean column.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame.

required
value_column str

Name of the boolean column to analyze. Default "value_bool".

'value_bool'

Returns:

Type Description
int

Number of True values.

count_false classmethod ¤

count_false(
    dataframe: DataFrame, value_column: str = "value_bool"
) -> int

Returns the count of False values in the boolean column.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame.

required
value_column str

Name of the boolean column to analyze. Default "value_bool".

'value_bool'

Returns:

Type Description
int

Number of False values.

count_null classmethod ¤

count_null(
    dataframe: DataFrame, value_column: str = "value_bool"
) -> int

Returns the count of null (NaN) values in the boolean column.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame.

required
value_column str

Name of the boolean column to analyze. Default "value_bool".

'value_bool'

Returns:

Type Description
int

Number of missing values.

count_not_null classmethod ¤

count_not_null(
    dataframe: DataFrame, value_column: str = "value_bool"
) -> int

Returns the count of non-null (True or False) values in the boolean column.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame.

required
value_column str

Name of the boolean column to analyze. Default "value_bool".

'value_bool'

Returns:

Type Description
int

Number of True or False values.

true_percentage classmethod ¤

true_percentage(
    dataframe: DataFrame, value_column: str = "value_bool"
) -> float

Returns the percentage of True values in the boolean column.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame.

required
value_column str

Name of the boolean column to analyze. Default "value_bool".

'value_bool'

Returns:

Type Description
float

Percentage (0-100) of the non-null values that are True; NaN when the column holds no non-null value.

false_percentage classmethod ¤

false_percentage(
    dataframe: DataFrame, value_column: str = "value_bool"
) -> float

Returns the percentage of False values in the boolean column.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame.

required
value_column str

Name of the boolean column to analyze. Default "value_bool".

'value_bool'

Returns:

Type Description
float

Percentage (0-100) of the non-null values that are False; NaN when the column holds no non-null value.

mode classmethod ¤

mode(
    dataframe: DataFrame, value_column: str
) -> bool | None

Returns the mode (most common value) of the specified boolean column.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame.

required
value_column str

Name of the boolean column to analyze.

required

Returns:

Type Description
bool | None

The most common non-null value (False on a tie), or None when the column holds no non-null value.

is_balanced classmethod ¤

is_balanced(
    dataframe: DataFrame, value_column: str
) -> bool

Indicates if the distribution is balanced (50% True and False) in the specified boolean column.

The check is exact on counts: the column is balanced when twice the number of True values equals the number of non-null values. Nulls are ignored, and an empty (or all-null) column is not balanced.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame.

required
value_column str

Name of the boolean column to analyze.

required

Returns:

Type Description
bool

True when exactly half of the non-null values are True.

summary_as_dict classmethod ¤

summary_as_dict(
    dataframe: DataFrame, value_column: str
) -> dict[str, int | float | bool | None]

Returns a summary of boolean statistics for the specified column as a dictionary.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame.

required
value_column str

Name of the boolean column to analyze.

required

Returns:

Type Description
dict[str, int | float | bool | None]

Dict with keys true_count, false_count, true_percentage, false_percentage, mode and is_balanced.

summary_as_dataframe classmethod ¤

summary_as_dataframe(
    dataframe: DataFrame, value_column: str
) -> pd.DataFrame

Returns a summary of boolean statistics for the specified column as a DataFrame.

Parameters:

Name Type Description Default
dataframe DataFrame

Input DataFrame.

required
value_column str

Name of the boolean column to analyze.

required

Returns:

Type Description
DataFrame

One-row DataFrame with the keys of summary_as_dict as columns.