Loading...

vastorbit.VastFrame.cummax

VastFrame.cummax(column: str, by: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, order_by: None | dict | list = None, name: str | None = None) VastFrame

Adds a new VastColumn to the VastFrame by computing the cumulative maximum of the input VastColumn.

Warning

Make use of the order_by parameter to sort your data. Otherwise, you might encounter unexpected results, as databases do not work with indexes, and the data may be randomly shuffled.

Parameters:
  • column (str) – Input VastColumn.

  • by (list, optional) – VastColumns used in the partition.

  • order_by (dict | list, optional) – List of the VastColumn used to sort the data using ascending/descending order or a dictionary of all the sorting methods. For example, to sort by “column1” ASC and “column2” DESC, use: {"column1": "asc", "column2": "desc"}.

  • name (str, optional) – Name of the new VastColumn. If empty, a default name is generated.

Returns:

self

Return type:

VastFrame

Examples

Let’s begin by importing vastorbit.

import vastorbit as vo

Hint

By assigning an alias to vastorbit, we mitigate the risk of code collisions with other libraries. This precaution is necessary because vastorbit uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from vastorbit are used as intended without interfering with functions from other libraries.

For this example, let’s generate the following dataset:

vdf = vo.VastFrame(
    {
        "id": [0, 1, 2, 3, 4, 5, 6],
        "sale": [100, 120, 120, 110, 100, 90, 80],
    }
)
123
id
Integer
123
sale
Integer
14100
2680
33110
4590
52120
61120
70100
Rows: 1-7 | Columns: 2

Now the cumulative maximum of the selected column can be easily calculated:

vdf.cummax(
    "sale",
    name = "cummax_sales",
    order_by = "id",
)
123
id
Integer
123
sale
Integer
123
cummax_sales
Integer
10100100
21120120
32120120
43110120
54100120
6590120
7680120
Rows: 1-7 | Columns: 3

Note

Rolling windows are valuable in time-series data for creating features because they allow us to analyze a specified number of past data points at each step. This approach is useful for capturing trends over time, adapting to different time scales, and smoothing out noise in the data. By applying aggregation functions within these windows, such as calculating averages or sums, we can generate new features that provide insights into the historical patterns of the dataset. These features, based on past observations, contribute to building more informed and predictive models, enhancing our understanding of the underlying trends in the data.

See also

VastFrame.rolling() : Advanced analytical window function.