Skip to main content
`Ctrl`+`K`

# pandas.Timedelta.as_unit

Timedelta.as_unit(unit, round_ok=True)

  Convert the underlying int64 representation to the given unit.

  Converts the Timedelta to a new resolution specified by `unit`. If the conversion would require rounding (loss of precision), this is allowed by default. Set `round_ok=False` to raise an error instead.

  Parameters:
    unit{“ns”, “us”, “ms”, “s”}
    round_ok bool, default True

      If False and the conversion requires rounding, raise.

  Returns:
    Timedelta

  See also

  `Timedelta`

    Represents a duration, the difference between two dates or times.

  `to_timedelta`

    Convert argument to timedelta.

  `Timedelta.asm8`

    Return a numpy timedelta64 array scalar view.

  Examples

      >>> td = pd.Timedelta('1001ms')
      >>> td
      Timedelta('0 days 00:00:01.001000')
      >>> td.as_unit('s')
      Timedelta('0 days 00:00:01')