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
VastColumnto theVastFrameby computing the cumulative maximum of the inputVastColumn.Warning
Make use of the
order_byparameter 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
VastColumnused 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:
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 fromvastorbitare 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], } )
123idInteger123saleInteger1 4 100 2 6 80 3 3 110 4 5 90 5 2 120 6 1 120 7 0 100 Rows: 1-7 | Columns: 2Now the cumulative maximum of the selected column can be easily calculated:
vdf.cummax( "sale", name = "cummax_sales", order_by = "id", )
123idInteger123saleInteger123cummax_salesInteger1 0 100 100 2 1 120 120 3 2 120 120 4 3 110 120 5 4 100 120 6 5 90 120 7 6 80 120 Rows: 1-7 | Columns: 3Note
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.