bigframes.pandas.to_timedelta#

bigframes.pandas.to_timedelta(arg, unit: Literal['W', 'w', 'D', 'd', 'days', 'day', 'hours', 'hour', 'hr', 'h', 'm', 'minute', 'min', 'minutes', 's', 'seconds', 'sec', 'second', 'ms', 'milliseconds', 'millisecond', 'milli', 'millis', 'us', 'microseconds', 'microsecond', 'µs', 'micro', 'micros'] | None = None, *, session: Session | None = None)[source]#

Converts a scalar or Series to a timedelta object.

Note

BigQuery only supports precision up to microseconds (us). Therefore, when working with timedeltas that have a finer granularity than microseconds, be aware that the additional precision will not be represented in BigQuery.

Examples:

Converting a Scalar to timedelta

>>> import bigframes.pandas as bpd
>>> scalar = 2
>>> bpd.to_timedelta(scalar, unit='s')
Timedelta('0 days 00:00:02')

Converting a Series of integers to a Series of timedeltas

>>> int_series = bpd.Series([1,2,3])
>>> bpd.to_timedelta(int_series, unit='s')
0    0 days 00:00:01
1    0 days 00:00:02
2    0 days 00:00:03
dtype: duration[us][pyarrow]
Parameters:
  • arg (int, float, str, Series) – The object to convert to a dataframe

  • unit (str, default 'us') –

    Denotes the unit of the arg for numeric arg. Defaults to "us".

    Possible values:

    • ’W’

    • ’D’ / ‘days’ / ‘day’

    • ’hours’ / ‘hour’ / ‘hr’ / ‘h’ / ‘H’

    • ’m’ / ‘minute’ / ‘min’ / ‘minutes’

    • ’s’ / ‘seconds’ / ‘sec’ / ‘second’

    • ’ms’ / ‘milliseconds’ / ‘millisecond’ / ‘milli’ / ‘millis’

    • ’us’ / ‘microseconds’ / ‘microsecond’ / ‘micro’ / ‘micros’

Returns:

Return type depends on input - Series: Series of duration[us][pyarrow] dtype - scalar: timedelta

Return type:

Union[pandas.Timedelta, bigframes.pandas.Series]