tidypolars.lubridate

Module Contents

Functions

as_date(x[, fmt])

Convert a string to a Date

as_datetime(x[, fmt])

Convert a string to a Datetime

hour(x)

Extract the hour from a datetime

mday(x)

Extract the month day from a date from 1 to 31.

make_date([year, month, day])

Create a date object

make_datetime([year, month, day, hour, minute, second])

Create a datetime object

minute(x)

Extract the minute from a datetime

month(x)

Extract the month from a date

quarter(x)

Extract the quarter from a date

dt_round(x, rule, n)

Round the datetime

second(x)

Extract the second from a datetime

wday(x)

Extract the weekday from a date from sunday = 1 to saturday = 7.

week(x)

Extract the week from a date

yday(x)

Extract the year day from a date from 1 to 366.

year(x)

Extract the year from a date

as_date(x, fmt=None)[source]

Convert a string to a Date

Parameters:
  • x (Expr, Series) – Column to operate on

  • fmt (str) – “yyyy-mm-dd”

Examples

>>> df = tp.Tibble(x = ['2021-01-01', '2021-10-01'])
>>> df.mutate(date_x = tp.as_date(col('x')))
as_datetime(x, fmt=None)[source]

Convert a string to a Datetime

Parameters:
  • x (Expr, Series) – Column to operate on

  • fmt (str) – “yyyy-mm-dd”

Examples

>>> df = tp.Tibble(x = ['2021-01-01', '2021-10-01'])
>>> df.mutate(date_x = tp.as_datetime(col('x')))
hour(x)[source]

Extract the hour from a datetime

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(hour = tp.as_hour(col('x')))
mday(x)[source]

Extract the month day from a date from 1 to 31.

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(monthday = tp.mday(col('x')))
make_date(year=1970, month=1, day=1)[source]

Create a date object

Parameters:
  • year (Expr, str, int) – Column or literal

  • month (Expr, str, int) – Column or literal

  • day (Expr, str, int) – Column or literal

Examples

>>> df.mutate(date = tp.make_date(2000, 1, 1))
make_datetime(year=1970, month=1, day=1, hour=0, minute=0, second=0)[source]

Create a datetime object

Parameters:
  • year (Expr, str, int) – Column or literal

  • month (Expr, str, int) – Column or literal

  • day (Expr, str, int) – Column or literal

  • hour (Expr, str, int) – Column or literal

  • minute (Expr, str, int) – Column or literal

  • second (Expr, str, int) – Column or literal

Examples

>>> df.mutate(date = tp.make_datetime(2000, 1, 1))
minute(x)[source]

Extract the minute from a datetime

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(hour = tp.minute(col('x')))
month(x)[source]

Extract the month from a date

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(year = tp.month(col('x')))
quarter(x)[source]

Extract the quarter from a date

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(quarter = tp.quarter(col('x')))
dt_round(x, rule, n)[source]

Round the datetime

Parameters:
  • x (Expr, Series) – Column to operate on

  • rule (str) –

    Units of the downscaling operation. Any of:

    • ”month”

    • ”week”

    • ”day”

    • ”hour”

    • ”minute”

    • ”second”

  • n (int) – Number of units (e.g. 5 “day”, 15 “minute”.

Examples

>>> df.mutate(monthday = tp.mday(col('x')))
second(x)[source]

Extract the second from a datetime

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(hour = tp.minute(col('x')))
wday(x)[source]

Extract the weekday from a date from sunday = 1 to saturday = 7.

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(weekday = tp.wday(col('x')))
week(x)[source]

Extract the week from a date

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(week = tp.week(col('x')))
yday(x)[source]

Extract the year day from a date from 1 to 366.

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(yearday = tp.yday(col('x')))
year(x)[source]

Extract the year from a date

Parameters:

x (Expr, Series) – Column to operate on

Examples

>>> df.mutate(year = tp.year(col('x')))