ts_shape.features.stats.boolean_stats
Classes
| Name | Description |
|---|
BooleanStatistics | Provides class methods to calculate statistics on a boolean column in a pandas DataFrame. |
Bases: Base
Provides class methods to calculate statistics on a boolean column in a pandas DataFrame.
Functions
| Name | Description |
|---|
count_true | Returns the count of True values in the boolean column. |
count_false | Returns the count of False values in the boolean column. |
count_null | Returns the count of null (NaN) values in the boolean column. |
count_not_null | Returns the count of non-null (True or False) values in the boolean column. |
true_percentage | Returns the percentage of True values in the boolean column. |
false_percentage | Returns the percentage of False values in the boolean column. |
mode | Returns the mode (most common value) of the specified boolean column. |
is_balanced | Indicates if the distribution is balanced (50% True and False) in the specified boolean column. |
summary_as_dict | Returns a summary of boolean statistics for the specified column as a dictionary. |
summary_as_dataframe | Returns a summary of boolean statistics for the specified column as a DataFrame. |
count_true(dataframe: pd.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(dataframe: pd.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(dataframe: pd.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(
dataframe: pd.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(
dataframe: pd.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(
dataframe: pd.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(dataframe: pd.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(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
| 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(
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
| 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(
dataframe: pd.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. |