Skip to main content
Version: 0.0.98

ts_shape.features.time_stats.time_stats_numeric

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

TimeGroupedStatistics​

classsource

Bases: Base

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

Functions
NameDescription
calculate_statisticCalculate a specified statistic on the value column over the grouped time intervals.
calculate_statisticsCalculate multiple specified statistics on the value column over the grouped time intervals.
calculate_custom_funcApply a custom aggregation function on the value column over the grouped time intervals.

calculate_statistic​

classmethodsource
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
NameTypeDescriptionDefault
dataframeDataFrameThe DataFrame containing the data.required
time_columnstrThe name of the time column to group and sort by. Default "systime".'systime'
value_columnstrThe name of the numeric column to calculate statistics on. Default "value_double".'value_double'
windowstrFrequency 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_methodstrThe statistical method to apply ('mean', 'sum', 'min', 'max', 'diff', 'range'). Default 'mean'.'mean'
group_by_uuidboolWhen 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_resetsboolFor '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
flatboolWhen 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
TypeDescription
DataFramepd.DataFrame: A DataFrame with the time intervals and the calculated statistics.

calculate_statistics​

classmethodsource
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
NameTypeDescriptionDefault
dataframeDataFrameThe DataFrame containing the data.required
time_columnstrThe name of the time column to group and sort by. Default "systime".'systime'
value_columnstrThe name of the numeric column to calculate statistics on. Default "value_double".'value_double'
windowstrFrequency 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_methodslistA list of statistical methods to apply (e.g., ['mean', 'sum', 'diff', 'range']). Default ['mean', 'min', 'max'].None
group_by_uuidboolSee :meth:calculate_statistic.True
handle_resetsboolSee :meth:calculate_statistic.True
flatboolSee :meth:calculate_statistic.False
Returns
TypeDescription
DataFramepd.DataFrame: A DataFrame with the time intervals and the calculated statistics for each method.

calculate_custom_func​

classmethodsource
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
NameTypeDescriptionDefault
dataframeDataFrameThe DataFrame containing the data.required
time_columnstrThe name of the time column to group and sort by. Default "systime".'systime'
value_columnstrThe name of the numeric column to calculate statistics on. Default "value_double".'value_double'
windowstrFrequency string for time grouping (e.g., 'h' for hourly, 'D' for daily; pandas 3 rejects 'H'). Default "1h". freq is the deprecated name.'1h'
funccallableCustom function to apply to each group (required).None
group_by_uuidboolSee :meth:calculate_statistic.True
flatboolSee :meth:calculate_statistic.False
Returns
TypeDescription
DataFramepd.DataFrame: A DataFrame with the custom calculated statistics in the column custom, indexed by time window (and uuid when grouping by uuid).