extract

In [ ]:
extract(expr, field: str)

Extracts a sub-field such as year or hour from a date/time expression.

Parameters

Name Type Optional Description
expr
object
❌
Expression.
field
str
❌
The field to extract. It must be one of the following:
CENTURY / DAY / DECADE / DOQ / DOW / DOY / EPOCH / HOUR / ISODOW / ISOWEEK / ISOYEAR / MICROSECONDS / MILLENNIUM / MILLISECONDS / MINUTE / MONTH / QUARTER / SECOND / TIME ZONE / TIMEZONE_HOUR / TIMEZONE_MINUTE / WEEK / YEAR

Returns

str_sql : SQL expression.

Example

In [2]:
from verticapy import *
df = tablesample({"x": ['11-03-1993', '12-03-1993']}).to_vdf()
df["x"].astype("timestamp")
display(df)
📅
x
Timestamp
11993-11-03 00:00:00
21993-12-03 00:00:00
Rows: 1-2 | Column: x | Type: timestamp
In [3]:
# Importing the stats module
import verticapy.stats as st

# Applying the extract function
df["months"] = st.extract(df["x"], "MONTH")
display(df)
📅
x
Timestamp
123
months
Numeric(18,0)
11993-11-03 00:00:0011.0
21993-12-03 00:00:0012.0
Rows: 1-2 | Columns: 2