Skip to main content
Version: Next

ts_shape.features.stats.boolean_stats

Classes
NameDescription
BooleanStatisticsProvides class methods to calculate statistics on a boolean column in a pandas DataFrame.

BooleanStatistics​

classsource

Bases: Base

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

Functions
NameDescription
count_trueReturns the count of True values in the boolean column.
count_falseReturns the count of False values in the boolean column.
count_nullReturns the count of null (NaN) values in the boolean column.
count_not_nullReturns the count of non-null (True or False) values in the boolean column.
true_percentageReturns the percentage of True values in the boolean column.
false_percentageReturns the percentage of False values in the boolean column.
modeReturns the mode (most common value) of the specified boolean column.
is_balancedIndicates if the distribution is balanced (50% True and False) in the specified boolean column.
summary_as_dictReturns a summary of boolean statistics for the specified column as a dictionary.
summary_as_dataframeReturns a summary of boolean statistics for the specified column as a DataFrame.

count_true​

classmethodsource
count_true(dataframe: pd.DataFrame, value_column: str = 'value_bool') -> int

Returns the count of True values in the boolean column.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame.required
value_columnstrName of the boolean column to analyze. Default "value_bool".'value_bool'
Returns
TypeDescription
intNumber of True values.

count_false​

classmethodsource
count_false(dataframe: pd.DataFrame, value_column: str = 'value_bool') -> int

Returns the count of False values in the boolean column.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame.required
value_columnstrName of the boolean column to analyze. Default "value_bool".'value_bool'
Returns
TypeDescription
intNumber of False values.

count_null​

classmethodsource
count_null(dataframe: pd.DataFrame, value_column: str = 'value_bool') -> int

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

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame.required
value_columnstrName of the boolean column to analyze. Default "value_bool".'value_bool'
Returns
TypeDescription
intNumber of missing values.

count_not_null​

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

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

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame.required
value_columnstrName of the boolean column to analyze. Default "value_bool".'value_bool'
Returns
TypeDescription
intNumber of True or False values.

true_percentage​

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

Returns the percentage of True values in the boolean column.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame.required
value_columnstrName of the boolean column to analyze. Default "value_bool".'value_bool'
Returns
TypeDescription
floatPercentage (0-100) of the non-null values that are True; NaN when the column holds no non-null value.

false_percentage​

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

Returns the percentage of False values in the boolean column.

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame.required
value_columnstrName of the boolean column to analyze. Default "value_bool".'value_bool'
Returns
TypeDescription
floatPercentage (0-100) of the non-null values that are False; NaN when the column holds no non-null value.

mode​

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

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

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame.required
value_columnstrName of the boolean column to analyze.required
Returns
TypeDescription
bool | NoneThe most common non-null value (False on a tie), or None when the column holds no non-null value.

is_balanced​

classmethodsource
is_balanced(dataframe: pd.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
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame.required
value_columnstrName of the boolean column to analyze.required
Returns
TypeDescription
boolTrue when exactly half of the non-null values are True.

summary_as_dict​

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

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

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame.required
value_columnstrName of the boolean column to analyze.required
Returns
TypeDescription
dict[str, int | float | bool | None]Dict with keys true_count, false_count, true_percentage, false_percentage, mode and is_balanced.

summary_as_dataframe​

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

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

Parameters
NameTypeDescriptionDefault
dataframeDataFrameInput DataFrame.required
value_columnstrName of the boolean column to analyze.required
Returns
TypeDescription
DataFrameOne-row DataFrame with the keys of summary_as_dict as columns.