Skip to content

time_stats_numeric

time_stats_numeric ¤

TimeGroupedStatistics ¤

TimeGroupedStatistics(
    dataframe: DataFrame, time_column: str = "systime"
)

Bases: Base

A class for calculating time-grouped statistics on numeric data, with class methods to apply various statistical functions.

calculate_statistic classmethod ¤

calculate_statistic(
    dataframe: 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
) -> 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

Returns:

Type Description
DataFrame

pd.DataFrame: A DataFrame with the time intervals and the calculated statistics.

calculate_statistics classmethod ¤

calculate_statistics(
    dataframe: 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
) -> 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

Returns:

Type Description
DataFrame

pd.DataFrame: A DataFrame with the time intervals and the calculated statistics for each method.

calculate_custom_func classmethod ¤

calculate_custom_func(
    dataframe: DataFrame,
    time_column: str = "systime",
    value_column: str = "value_double",
    window: str = "1h",
    func: Callable[[Series], Any] | None = None,
    *,
    group_by_uuid: bool = True
) -> 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

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).