ts_shape.features.stats.numeric_stats
Classes
| Name | Description |
|---|
NumericStatistics | Provides class methods to calculate statistics on numeric columns in a pandas DataFrame. |
Bases: Base
Provides class methods to calculate statistics on numeric columns in a pandas DataFrame.
Functions
| Name | Description |
|---|
column_mean | Calculate the mean of a specified column. |
column_median | Calculate the median of a specified column. |
column_std | Calculate the standard deviation of a specified column. |
column_variance | Calculate the variance of a specified column. |
column_min | Calculate the minimum value of a specified column. |
column_max | Calculate the maximum value of a specified column. |
column_sum | Calculate the sum of a specified column. |
column_kurtosis | Calculate the kurtosis of a specified column. |
column_skewness | Calculate the skewness of a specified column. |
column_quantile | Calculate a specific quantile of the column. |
column_iqr | Calculate the interquartile range of the column. |
column_range | Calculate the range of the column. |
column_mad | Calculate the mean absolute deviation of the column. |
column_mode | Calculate the mode of a specified column. Returns None if column is empty. |
coefficient_of_variation | Calculate the coefficient of variation of the column. |
standard_error_mean | Calculate the standard error of the mean for the column. |
describe | Provide a statistical summary for numeric columns in the DataFrame. |
summary_as_dict | Returns a dictionary with comprehensive numeric statistics for the specified column. |
summary_as_dataframe | Returns a DataFrame with comprehensive numeric statistics for the specified column. |
column_mean(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the mean of a specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The mean of the non-missing values; NaN when there is none. |
column_median(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the median of a specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The median of the non-missing values; NaN when there is none. |
column_std(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the standard deviation of a specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The sample standard deviation (ddof=1); NaN for fewer than 2 values. |
column_variance(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the variance of a specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The sample variance (ddof=1); NaN for fewer than 2 values. |
column_min(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the minimum value of a specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The smallest value; NaN when there is none. |
column_max(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the maximum value of a specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The largest value; NaN when there is none. |
column_sum(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the sum of a specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The sum of the values; 0 when there is none. An integer column is summed exactly: in int64 when the sum cannot overflow (a numpy integer is returned, as before), otherwise with Python integers (a Python int), so a sum beyond the int64 range is not wrapped around. float64 is not used for this: it is exact only up to 2**53. |
column_kurtosis(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the kurtosis of a specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The bias-corrected excess kurtosis; NaN for fewer than 4 values. |
column_skewness(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the skewness of a specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The bias-corrected skewness; NaN for fewer than 3 values. |
column_quantile(
dataframe: pd.DataFrame, value_column: str, quantile: float
) -> float
Calculate a specific quantile of the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
quantile | float | Quantile to compute, between 0 and 1 (0.5 is the median). | required |
Returns
| Type | Description |
|---|
float | The quantile (linear interpolation); NaN when there is no value. |
column_iqr(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the interquartile range of the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | Third minus first quartile of the non-missing values; NaN when there is none. |
column_range(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the range of the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | Largest minus smallest value; NaN when there is none. For an integer column the difference is taken with Python integers, so it is exact and does not wrap around: an int64 result when it fits, else a Python int (e.g. 2**63 + 1 for [2**62 + 1, -2**62]). |
column_mad(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the mean absolute deviation of the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The mean absolute deviation from the mean; NaN when there is no value. |
column_mode(dataframe: pd.DataFrame, value_column: str) -> float | None
Calculate the mode of a specified column. Returns None if column is empty.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | None | The most frequent value (the smallest on a tie), or None when there is no value. |
coefficient_of_variation(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the coefficient of variation of the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | Standard deviation divided by the mean, or float("nan") when the |
float | mean is 0 (the ratio is undefined). |
standard_error_mean(dataframe: pd.DataFrame, value_column: str) -> float
Calculate the standard error of the mean for the column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
float | The standard error of the mean; NaN for fewer than 2 values. |
describe(dataframe: pd.DataFrame) -> pd.DataFrame
Provide a statistical summary for numeric columns in the DataFrame.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame; every numeric column is described. | required |
Returns
| Type | Description |
|---|
DataFrame | The output of DataFrame.describe(): one column per numeric column, rows count, mean, std, min, 25%, 50%, 75% and max. |
summary_as_dict(
dataframe: pd.DataFrame, value_column: str
) -> dict[str, float | int | None]
Returns a dictionary with comprehensive numeric statistics for the specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
dict[str, float | int | None] | Dict with keys min, max, mean, median, std, var, sum, kurtosis, skewness, q1, q3, iqr, range, mad, coeff_var, sem, mode, percentile_90 and percentile_10. |
summary_as_dataframe(
dataframe: pd.DataFrame, value_column: str
) -> pd.DataFrame
Returns a DataFrame with comprehensive numeric statistics for the specified column.
Parameters
| Name | Type | Description | Default |
|---|
dataframe | DataFrame | Input DataFrame. | required |
value_column | str | Name of the numeric column to analyze. | required |
Returns
| Type | Description |
|---|
DataFrame | One-row DataFrame with the keys of summary_as_dict as columns. |