maxframe.dataframe.Series.dt.floor#

Series.dt.floor(freq, ambiguous: Literal['infer', 'NaT', 'raise'] | bool | ndarray[Any, dtype[bool_]] = 'raise', nonexistent: Literal['shift_forward', 'shift_backward', 'NaT', 'raise'] | timedelta = 'raise') Self#

对数据执行向下取整操作,取整到指定的 freq

参数:
  • freq (str or Offset) -- The frequency level to floor the index to. Must be a fixed frequency like 's' (second) not 'ME' (month end). See frequency aliases for a list of possible freq values.

  • ambiguous ('infer', bool-ndarray, 'NaT', default 'raise') --

    仅对 DatetimeIndex 有效:

    • 'infer' 将根据顺序尝试推断夏令时转换时间

    • bool-ndarray,其中 True 表示夏令时时间,False 表示非夏令时时间(注意此标志仅适用于模糊时间)

    • 'NaT' 在存在模糊时间时将返回 NaT

    • 'raise' will raise a ValueError if there are ambiguous times.

  • nonexistent ('shift_forward', 'shift_backward', 'NaT', timedelta, default 'raise') --

    不存在的时间是指在特定时区中由于夏令时导致时钟向前移动而不存在的时间。

    • 'shift_forward' 将把不存在的时间向前移动到最接近的现有时间

    • 'shift_backward' 将把不存在的时间向后移动到最接近的现有时间

    • 'NaT' 在存在不存在的时间时将返回 NaT

    • timedelta 对象将按 timedelta 移动不存在的时间

    • 'raise' will raise a ValueError if there are nonexistent times.

返回:

DatetimeIndex 或 TimedeltaIndex 返回相同类型的索引,Series 返回具有相同索引的 Series。

返回类型:

DatetimeIndex, TimedeltaIndex, or Series

抛出:

ValueError if the freq cannot be converted. --

参见

DatetimeIndex.floor

对数据执行向下取整操作,取整到指定的 freq

DatetimeIndex.snap

Snap time stamps to nearest occurring frequency.

备注

如果时间戳具有时区信息,向下取整将相对于本地(“墙上”)时间进行,并重新本地化到同时区。在夏令时期间进行向下取整时,使用 nonexistentambiguous 来控制重新本地化的行为。

示例

DatetimeIndex

>>> import maxframe.dataframe as md
>>> rng = md.date_range("1/1/2018 11:59:00", periods=3, freq="min")
>>> rng.execute()
DatetimeIndex(['2018-01-01 11:59:00', '2018-01-01 12:00:00',
               '2018-01-01 12:01:00'],
              dtype='datetime64[us]', freq='min')
>>> rng.floor('h').execute()
DatetimeIndex(['2018-01-01 11:00:00', '2018-01-01 12:00:00',
               '2018-01-01 12:00:00'],
              dtype='datetime64[us]', freq=None)

Series

>>> md.Series(rng).dt.floor("h").execute()
0   2018-01-01 11:00:00
1   2018-01-01 12:00:00
2   2018-01-01 12:00:00
dtype: datetime64[us]

在夏令时转换时间附近进行取整时,使用 ambiguousnonexistent 来控制时间戳的重新本地化方式。

>>> rng_tz = md.DatetimeIndex(["2021-10-31 03:30:00"], tz="Europe/Amsterdam")
>>> rng_tz.floor("2h", ambiguous=False).execute()
DatetimeIndex(['2021-10-31 02:00:00+01:00'],
             dtype='datetime64[us, Europe/Amsterdam]', freq=None)
>>> rng_tz.floor("2h", ambiguous=True).execute()
DatetimeIndex(['2021-10-31 02:00:00+02:00'],
              dtype='datetime64[us, Europe/Amsterdam]', freq=None)