to_datetime#
- skrub.to_datetime(data, format=None)[source]#
Convert DataFrame or column to Datetime dtype.
Caution
For versions of Pandas <3.0, inferring the format may fail if it includes both date and time components, and the digits of the year are the same as the digits of the hour and minutes, like
"1959-07-01 19:59:16". In such cases, the format should be specified explicitly.- Parameters:
- datapandas or polars
{DataFrame, Series} The dataframe or series to transform.
- format
strorNone, optional, default=None Format string to use to parse datetime strings. See the reference documentation for format codes: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes .
- datapandas or polars
- Returns:
- outputpandas or polars {DataFrame,
Series}. The input transformed to Datetime.
- outputpandas or polars {DataFrame,
See also
ToDatetimeParse datetimes represented as strings and return Datetime columns.
Examples
>>> import pandas as pd >>> from skrub import to_datetime >>> X = pd.DataFrame(dict(a=[1, 2], b=["01/02/2021", "21/02/2021"])) >>> X a b 0 1 01/02/2021 1 2 21/02/2021 >>> to_datetime(X) a b 0 1 2021-02-01 1 2 2021-02-21