dataiter.dt

The dt module contains helper functions for dealing with vectors of dates and datetimes, similar to numpy.char for vectors of strings. Most of the operations are done via Python’s standard library datetime module and subject to any limitations therein.

day() from_string() hour() isoweek() isoweekday() microsecond() minute() month() new() now() quarter() replace() second() to_string() today() weekday() year()

dataiter.dt.day(x)[source]

Extract day of the month from datetime x.

>>> x = dt.new(["2022-10-15"])
>>> dt.day(x)
[ 15 ] int64
dataiter.dt.from_string(x, format)[source]

Initialize a datetime scalar or vector from x.

format uses Python strptime format codes: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes

>>> x = di.Vector(["15.10.2022"])
>>> dt.from_string(x, "%d.%m.%Y")
[ 2022-10-15 ] datetime64[D]
dataiter.dt.hour(x)[source]

Extract hour from datetime x.

>>> x = dt.new(["2022-10-15T12:34:56"])
>>> dt.hour(x)
[ 12 ] int64
dataiter.dt.isoweek(x)[source]

Extract ISO 8601 week from datetime x.

>>> x = dt.new(["2022-10-15"])
>>> dt.isoweek(x)
[ 41 ] int64
dataiter.dt.isoweekday(x)[source]

Extract day of the week from datetime x.

Day of the week is an integer between 1 and 7, where 1 is Monday and 7 is Sunday.

See also: weekday()

>>> x = dt.new(["2022-10-15"])
>>> dt.isoweekday(x)
[ 6 ] int64
dataiter.dt.microsecond(x)[source]

Extract microsecond from datetime x.

>>> x = dt.new(["2022-10-15T12:34:56.789"])
>>> dt.microsecond(x)
[ 789000 ] int64
dataiter.dt.minute(x)[source]

Extract minute from datetime x.

>>> x = dt.new(["2022-10-15T12:34:56"])
>>> dt.minute(x)
[ 34 ] int64
dataiter.dt.month(x)[source]

Extract month from datetime x.

>>> x = dt.new(["2022-10-15"])
>>> dt.month(x)
[ 10 ] int64
dataiter.dt.new(x)[source]

Initialize a datetime scalar or vector from x.

>>> dt.new("2022-10-15")
2022-10-15
>>> dt.new("2022-10-15T12:00:00")
2022-10-15T12:00:00
>>> dt.new(["2022-10-15"])
[ 2022-10-15 ] datetime64[D]
>>> dt.new(["2022-10-15T12:00:00"])
[ 2022-10-15T12:00:00 ] datetime64[s]
dataiter.dt.now()[source]

Return the current local datetime.

>>> dt.now()
2024-04-10T19:32:17.378834
dataiter.dt.quarter(x)[source]

Extract quarter from datetime x.

>>> x = dt.new(["2022-10-15"])
>>> dt.quarter(x)
[ 4 ] int64
dataiter.dt.replace(x, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None)[source]

Return datetime x with given components replaced.

>>> x = dt.new(["2022-10-15"])
>>> dt.replace(x, month=1, day=1)
[ 2022-01-01 ] datetime64[D]
dataiter.dt.second(x)[source]

Extract second from datetime x.

>>> x = dt.new(["2022-10-15T12:34:56"])
>>> dt.second(x)
[ 56 ] int64
dataiter.dt.to_string(x, format)[source]

Format datetime x as string.

format uses Python strftime format codes: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes

>>> x = dt.new(["2022-10-15"])
>>> dt.to_string(x, "%d.%m.%Y")
[ "15.10.2022" ] <U10
dataiter.dt.today()[source]

Return the current local date.

>>> dt.today()
2024-04-10
dataiter.dt.weekday(x)[source]

Extract day of the week from datetime x.

Day of the week is an integer between 0 and 6, where 0 is Monday and 6 is Sunday.

See also: isoweekday()

>>> x = dt.new(["2022-10-15"])
>>> dt.weekday(x)
[ 5 ] int64
dataiter.dt.year(x)[source]

Extract year from datetime x.

>>> x = dt.new(["2022-10-15"])
>>> dt.year(x)
[ 2022 ] int64