maxframe.dataframe.Series.dt.ceil#

Series.dt.ceil(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 ceil 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。

返回类型:

DatetimeIndex, TimedeltaIndex, or Series

抛出:

ValueError if the freq cannot be converted. --

参见

DatetimeIndex.floor

Perform floor operation on the data to the specified 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.ceil('h').execute()
DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
               '2018-01-01 13:00:00'],
              dtype='datetime64[us]', freq=None)

Series

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

在夏令时转换附近进行取整时,使用 ambiguousnonexistent 控制时间戳应如何重新本地化。

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