Loading...

vastorbit.VastColumn.date_part

VastColumn.date_part(field: str) VastFrame

Extracts a specific TS field from the VastColumn (only if the VastColumn type is date like). The VastColumn is transformed.

Parameters:

field (str) – The field to extract. It must be one of the following: century | day | decade | doq | dow | doy | epoch | hour | isodow | isoweek | isoyear | millennium | milliseconds | minute | month | quarter | second | timezone | timezone_hour | timezone_minute | week | year

Returns:

self._parent

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.

Let us create a dummy dataset that has timestamp values:

vdf = vo.VastFrame(
    {
        "time": [
            "1993-11-03 00:00:00",
            "1993-11-04 00:00:01",
            "1993-11-05 00:00:02",
            "1993-11-06 00:00:04",
            "1993-11-07 00:00:05",
        ],
        "val": [0., 1., 2., 4.,5.],
    }
)
Abc
time
Varchar(19)
123
val
Decimal(2, 1)
11993-11-06 00:00:044.0
21993-11-07 00:00:055.0
31993-11-03 00:00:000.0
41993-11-05 00:00:022.0
51993-11-04 00:00:011.0
Rows: 1-5 | Columns: 2

We can make sure that the column has the correct data type:

vdf["time"].astype("timestamp")

Next, we can apply the date_part function to get the required temporal details:

vdf["time"].date_part(field = "day")
123
time
Bigint
123
val
Decimal(2, 1)
152.0
275.0
330.0
441.0
564.0
Rows: 1-5 | Columns: 2

Note

While the same task can be accomplished using pure SQL (see below), adopting a Pythonic approach can offer greater convenience and help avoid potential syntax errors.

vdf["val"] = "EXTRACT(DAY FROM val)"

See also

VastColumn.slice() : Slice the VastColumn by custom time-steps.