ts_shape.features.time_stats.time_stats_numeric
Classes
| Name | Description |
|---|---|
TimeGroupedStatistics | A class for calculating time-grouped statistics on numeric data, with class methods to apply various statistical functions. |
TimeGroupedStatistics
Bases: Base
A class for calculating time-grouped statistics on numeric data, with class methods to apply various statistical functions.
Functions
| Name | Description |
|---|---|
calculate_statistic | Calculate a specified statistic on the value column over the grouped time intervals. |
calculate_statistics | Calculate multiple specified statistics on the value column over the grouped time intervals. |
calculate_custom_func | Apply a custom aggregation function on the value column over the grouped time intervals. |
calculate_statistic
calculate_statistic(
dataframe: pd.DataFrame,
time_column: str = "systime",
value_column: str = "value_double",
window: str = "1h",
stat_method: str = "mean",
*,
group_by_uuid: bool = True,
handle_resets: bool = True,
flat: bool = False
) -> pd.DataFrame
Calculate a specified statistic on the value column over the grouped time intervals.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | The DataFrame containing the data. | required |
time_column | str | The name of the time column to group and sort by. Default "systime". | 'systime' |
value_column | str | The name of the numeric column to calculate statistics on. Default "value_double". | 'value_double' |
window | str | Frequency string for time grouping (e.g., 'h' for hourly, 'D' for daily; pandas 3 rejects 'H'). Default "1h". freq is the deprecated name. | '1h' |
stat_method | str | The statistical method to apply ('mean', 'sum', 'min', 'max', 'diff', 'range'). Default 'mean'. | 'mean' |
group_by_uuid | bool | When True (default) and the frame has a uuid column, compute the statistic per uuid (result indexed by uuid and time), so signals are never mixed. False pools every row into one series. A frame without a uuid column is always treated as one series. | True |
handle_resets | bool | For 'diff': when True (default) the column is treated as a cumulative counter and the reset-aware increments are summed per interval (see :func:ts_shape.utils.counters.counter_per_window). When False the result is last - first within each interval, which is the right choice for a signal that is not a counter (it goes negative across a counter reset). Ignored for the other methods. | True |
flat | bool | When True return a long-format frame with window_start (and uuid when grouping by uuid) as plain columns and no index of meaning, so the result composes with the rest of the library's long-format API. Default False keeps the historical MultiIndex/DatetimeIndex shape. | False |
Returns
| Type | Description |
|---|---|
DataFrame | pd.DataFrame: A DataFrame with the time intervals and the calculated statistics. |
calculate_statistics
calculate_statistics(
dataframe: pd.DataFrame,
time_column: str = "systime",
value_column: str = "value_double",
window: str = "1h",
stat_methods: list[str] | None = None,
*,
group_by_uuid: bool = True,
handle_resets: bool = True,
flat: bool = False
) -> pd.DataFrame
Calculate multiple specified statistics on the value column over the grouped time intervals.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | The DataFrame containing the data. | required |
time_column | str | The name of the time column to group and sort by. Default "systime". | 'systime' |
value_column | str | The name of the numeric column to calculate statistics on. Default "value_double". | 'value_double' |
window | str | Frequency string for time grouping (e.g., 'h' for hourly, 'D' for daily; pandas 3 rejects 'H'). Default "1h". freq is the deprecated name. | '1h' |
stat_methods | list | A list of statistical methods to apply (e.g., ['mean', 'sum', 'diff', 'range']). Default ['mean', 'min', 'max']. | None |
group_by_uuid | bool | See :meth:calculate_statistic. | True |
handle_resets | bool | See :meth:calculate_statistic. | True |
flat | bool | See :meth:calculate_statistic. | False |
Returns
| Type | Description |
|---|---|
DataFrame | pd.DataFrame: A DataFrame with the time intervals and the calculated statistics for each method. |
calculate_custom_func
calculate_custom_func(
dataframe: pd.DataFrame,
time_column: str = "systime",
value_column: str = "value_double",
window: str = "1h",
func: Callable[[pd.Series], Any] | None = None,
*,
group_by_uuid: bool = True,
flat: bool = False
) -> pd.DataFrame
Apply a custom aggregation function on the value column over the grouped time intervals.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
dataframe | DataFrame | The DataFrame containing the data. | required |
time_column | str | The name of the time column to group and sort by. Default "systime". | 'systime' |
value_column | str | The name of the numeric column to calculate statistics on. Default "value_double". | 'value_double' |
window | str | Frequency string for time grouping (e.g., 'h' for hourly, 'D' for daily; pandas 3 rejects 'H'). Default "1h". freq is the deprecated name. | '1h' |
func | callable | Custom function to apply to each group (required). | None |
group_by_uuid | bool | See :meth:calculate_statistic. | True |
flat | bool | See :meth:calculate_statistic. | False |
Returns
| Type | Description |
|---|---|
DataFrame | pd.DataFrame: A DataFrame with the custom calculated statistics in the column custom, indexed by time window (and uuid when grouping by uuid). |