ts_shape.features.stats.string_stats
Classes
| Name | Description |
|---|
StringStatistics | Provides class methods to calculate statistics on string columns in a pandas DataFrame. |
Bases: Base
Provides class methods to calculate statistics on string columns in a pandas DataFrame.
Functions
count_unique(
dataframe: pd.DataFrame, value_column: str = "value_string"
) -> int
Returns the number of unique strings in the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
int | Number of distinct non-null values. |
most_frequent(
dataframe: pd.DataFrame, value_column: str = "value_string"
) -> str | None
Returns the most frequent string in the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
str | None | The most frequent non-null string (the smallest on ties), or |
str | None | None when the column holds no non-null value. |
count_most_frequent(
dataframe: pd.DataFrame, value_column: str = "value_string"
) -> int
Returns the count of the most frequent string in the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
int | Occurrences of :meth:most_frequent; 0 when the column holds |
int | no non-null value (it raised IndexError before). |
count_null(dataframe: pd.DataFrame, value_column: str = 'value_string') -> int
Returns the number of null (NaN) values in the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
int | Number of missing values. |
average_string_length(
dataframe: pd.DataFrame, value_column: str = "value_string"
) -> float
Returns the average length of strings in the column, excluding null values.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
float | Mean length of the non-null strings; NaN when there is none. |
longest_string(
dataframe: pd.DataFrame, value_column: str = "value_string"
) -> str | None
Returns the longest string in the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
str | None | The longest non-null string, or None when the column holds no |
str | None | non-null value. |
shortest_string(
dataframe: pd.DataFrame, value_column: str = "value_string"
) -> str | None
Returns the shortest string in the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
str | None | The shortest non-null string, or None when the column holds no |
str | None | non-null value. |
string_length_summary(
dataframe: pd.DataFrame, value_column: str = "value_string"
) -> pd.DataFrame
Returns a summary of string lengths, including min, max, and average lengths.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
DataFrame | One-row DataFrame with columns Min Length, Max Length and Average Length (null values excluded). |
most_common_n_strings(
dataframe: pd.DataFrame, n: int, value_column: str = "value_string"
) -> pd.Series
Returns the top N most frequent strings in the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
n | int | Number of strings to return. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
Series | Series of counts indexed by string, most frequent first. |
contains_substring_count(
dataframe: pd.DataFrame,
substring: str,
value_column: str = "value_string",
*,
regex: bool = False
) -> int
Counts how many strings contain the specified substring.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
substring | str | Text to look for, matched literally by default, so characters such as ., ( or + have no special meaning. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
regex | bool | If False (default), match substring literally; if True, treat it as a regular expression. | False |
Returns
| Type | Description |
|---|
int | Number of non-null strings that contain substring. |
starts_with_count(
dataframe: pd.DataFrame, prefix: str, value_column: str = "value_string"
) -> int
Counts how many strings start with the specified prefix.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
prefix | str | Prefix to match. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
int | Number of non-null strings that start with prefix. |
ends_with_count(
dataframe: pd.DataFrame, suffix: str, value_column: str = "value_string"
) -> int
Counts how many strings end with the specified suffix.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
suffix | str | Suffix to match. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
int | Number of non-null strings that end with suffix. |
uppercase_percentage(
dataframe: pd.DataFrame, value_column: str = "value_string"
) -> float
Returns the percentage of strings that are fully uppercase.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
float | Percentage (0-100) of the non-null strings that are fully uppercase; NaN when the column holds no non-null value. |
lowercase_percentage(
dataframe: pd.DataFrame, value_column: str = "value_string"
) -> float
Returns the percentage of strings that are fully lowercase.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
float | Percentage (0-100) of the non-null strings that are fully lowercase; NaN when the column holds no non-null value. |
contains_digit_count(
dataframe: pd.DataFrame, value_column: str = "value_string"
) -> int
Counts how many strings contain digits.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. Default "value_string". | 'value_string' |
Returns
| Type | Description |
|---|
int | Number of non-null strings with at least one digit. |
summary_as_dict(
dataframe: pd.DataFrame, value_column: str
) -> dict[str, int | str | float | None]
Returns a dictionary with comprehensive string statistics for the specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. | required |
Returns
| Type | Description |
|---|
dict[str, int | str | float | None] | Dict with keys unique_values, most_frequent, count_most_frequent, count_null, average_string_length, longest_string, shortest_string, uppercase_percentage, lowercase_percentage, contains_digit_count, least_common and frequency_least_common. |
summary_as_dataframe(
dataframe: pd.DataFrame, value_column: str
) -> pd.DataFrame
Returns a DataFrame with comprehensive string statistics for the specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the string column to analyze. | required |
Returns
| Type | Description |
|---|
DataFrame | One-row DataFrame with the keys of summary_as_dict as columns. |