cudf.to_datetime#

cudf.to_datetime(
arg,
errors: Literal['raise', 'coerce', 'warn', 'ignore'] = 'raise',
dayfirst: bool = False,
yearfirst: bool = False,
utc: bool = False,
format: str | None = None,
exact: bool = True,
unit: str | None = None,
origin='unix',
cache: bool = True,
)[source]#

Convert argument to datetime.

Parameters:
argint, float, str, datetime, list, tuple, 1-d array,

Series DataFrame/dict-like The object to convert to a datetime.

errors{‘ignore’, ‘raise’, ‘coerce’, ‘warn’}, default ‘raise’
  • If ‘raise’, then invalid parsing will raise an exception.

  • If ‘coerce’, then invalid parsing will be set as NaT.

  • If ‘warn’prints last exceptions as warnings and

    return the input.

  • If ‘ignore’, then invalid parsing will return the input.

dayfirstbool, default False

Specify a date parse order if arg is str or its list-likes. If True, parses dates with the day first, eg 10/11/12 is parsed as 2012-11-10. Warning: dayfirst=True is not strict, but will prefer to parse with day first (this is a known bug, based on dateutil behavior).

utcbool, default False

Whether the result should be have a UTC timezone.

formatstr, default None

The strftime to parse time, eg “%d/%m/%Y”, note that “%f” will parse all the way up to nanoseconds. See strftime documentation for more information on choices: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior.

unitstr, default ‘ns’

The unit of the arg (D,s,ms,us,ns) denote the unit, which is an integer or float number. This will be based off the origin(unix epoch start). Example, with unit=’ms’ and origin=’unix’ (the default), this would calculate the number of milliseconds to the unix epoch start.

Returns:
datetime

If parsing succeeded. Return type depends on input: - list-like: DatetimeIndex - Series: Series of datetime64 dtype - scalar: Timestamp

Examples

Assembling a datetime from multiple columns of a DataFrame. The keys can be common abbreviations like [‘year’, ‘month’, ‘day’, ‘minute’, ‘second’, ‘ms’, ‘us’, ‘ns’]) or plurals of the same

>>> import cudf
>>> df = cudf.DataFrame({'year': [2015, 2016],
...                    'month': [2, 3],
...                    'day': [4, 5]})
>>> cudf.to_datetime(df)
0   2015-02-04
1   2016-03-05
dtype: datetime64[us]
>>> cudf.to_datetime(1490195805, unit='s')
Timestamp('2017-03-22 15:16:45')
>>> cudf.to_datetime(1490195805433502912, unit='ns')
Timestamp('2017-03-22 15:16:45.433502912')