vDataFrame.rolling¶
In [ ]:
vDataFrame.rolling(func: str,
window: (list, tuple),
columns: (str, list),
by: list = [],
order_by: (dict, list) = [],
name: str = "",)
Adds a new vcolumn to the vDataFrame by using an advanced analytical window function on one or two specific vcolumns.
⚠ Warning: Some window functions can significantly increase vDataFrame memory usage. You should always check the vDataFrame with the 'current_relation' method and save it with the 'to_db' method with the parameters 'inplace = True' and 'relation_type = table'
Parameters¶
| Name | Type | Optional | Description |
|---|---|---|---|
func | str | ❌ | Function to use.
|
window | list / tuple | ❌ | Window Frame Range. If two integers, it will compute a Row Window, otherwise it will compute a Time Window. For example, if set to (-5, 1), the moving windows will take 5 rows preceding and one following. If set to ('- 5 minutes', '0 minutes'), the moving window will take all the elements of the last 5 minutes. |
columns | str / list | ❌ | Input vcolumns. It can be a list of one or two elements. |
by | list | ✓ | vcolumns used in the partition. |
order_by | dict / list | ✓ | List of the vcolumns to use to sort the data using asc order or dictionary of all the sorting methods. For example, to sort by "column1" ASC and "column2" DESC, write {"column1": "asc", "column2": "desc"} |
name | str | ✓ | Name of the new vcolumn. If empty a default name based on the other parameters will be generated. |
Returns¶
vDataFrame : self
Example¶
In [1]:
from verticapy import vDataFrame
flights = vDataFrame("public.usa_flights")
display(flights)
In [2]:
# AVG delay using the 10 previous similar flights for the same airline
flights.rolling(func = "avg",
columns = "departure_delay",
window = (-10, -1),
by = ["origin_airport", "destination_airport", "airline"],
order_by = {"scheduled_departure": "asc"},)
Out[2]:
In [3]:
# Corr between arrival_delay and departure_delay using the 100 previous flights
# and the 10 following flights at the same airport
flights.rolling(func = "corr",
columns = ["departure_delay", "arrival_delay"],
window = (-100, 10),
by = ["origin_airport"],
order_by = {"scheduled_departure": "asc"},)
Out[3]:
In [4]:
# Number of flights the airline has to manage 2 hours preceding
# the flight and 1 hour following
flights.rolling(func = "count",
columns = "scheduled_departure",
window = ("- 2 hours", "1 hour"),
by = ["origin_airport", "airline"],
order_by = {"scheduled_departure": "asc"},)
Out[4]:
See Also¶
| vDataFrame.analytic | Adds a new vcolumn to the vDataFrame by using an advanced analytical function on a specific vcolumn. |
| vDataFrame.eval | Evaluates a customized expression. |
