Loading...

verticapy.vDataFrame.last#

vDataFrame.last(ts: str, offset: str) vDataFrame#

Filters the vDataFrame by only keeping the last records.

Parameters#

ts: str

TS (Time Series) vDataColumn used to filter the data. The vDataColumn type must be date (date, datetime, timestamp…)

offset: str

Interval offset. For example, to filter and keep only the last 6 months of records, offset should be set to ‘6 months’.

Returns#

vDataFrame

self

Examples#

We import verticapy:

import verticapy as vp

Hint

By assigning an alias to verticapy, we mitigate the risk of code collisions with other libraries. This precaution is necessary because verticapy 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 verticapy are used as intended without interfering with functions from other libraries.

For this example, we will use a dummy time-series data:

vdf = vp.vDataFrame(
    {
        "time": [
            "1993-11-01",
            "1993-11-02",
            "1993-11-03",
            "1993-11-04",
            "1993-11-05",
        ],
        "val": [0., 1., 2., 4., 5.],
    }
)

We can ensure that the data type is datetime.

vdf["time"].astype("datetime")
Out[3]: 
None                 time    val  
1    1993-11-01 00:00:00    0.0  
2    1993-11-02 00:00:00    1.0  
3    1993-11-03 00:00:00    2.0  
4    1993-11-04 00:00:00    4.0  
5    1993-11-05 00:00:00    5.0  
Rows: 5 | Columns: 2
📅
time
Datetime
100%
123
val
Numeric(4)
100%
11993-11-01 00:00:000.0
21993-11-02 00:00:001.0
31993-11-03 00:00:002.0
41993-11-04 00:00:004.0
51993-11-05 00:00:005.0

Note

VerticaPy offers a wide range of sample datasets that are ideal for training and testing purposes. You can explore the full list of available datasets in the Datasets, which provides detailed information on each dataset and how to use them effectively. These datasets are invaluable resources for honing your data analysis and machine learning skills within the VerticaPy environment.

Using last we can easily filter through to get the last set of values:

vdf.last(ts="time", offset="1 days")
📅
time
Datetime
100%
123
val
Numeric(4)
100%
11993-11-04 00:00:004.0
21993-11-05 00:00:005.0

See also

vDataFrame.first() : Filters the vDataFrame by only keeping the first records.
vDataFrame.at_time() : Filters the vDataFrame at a specific time.