- 用法:- DatetimeIndex.floor(*args, **kwargs)
- 对指定的 - freq的数据进行 floor 运算。- freq:str 或偏移量
- 将索引设为下限的频率级别。必须是固定频率,例如“S”(秒)而不是“ME”(月末)。有关可能的 - freq值的列表,请参阅频率别名。
- ambiguous:‘infer’, bool-ndarray, ‘NaT’, 默认 ‘raise’
- 仅与 DatetimeIndex 相关: - ‘infer’ 将尝试根据订单推断秋季 dst-transition 小时 
- bool-ndarray 其中 True 表示 DST 时间,False 表示非 DST 时间(请注意,此标志仅适用于模棱两可的时间) 
- 'NaT' 将在时间不明确的地方返回 NaT 
- 如果时间不明确,‘raise’ 将引发 AmbiguousTimeError。 
 
- nonexistent:‘shift_forward’, ‘shift_backward’, ‘NaT’, timedelta, 默认 ‘raise’
- 由于 DST,时钟向前移动的特定时区不存在不存在的时间。 - ‘shift_forward’ 将不存在的时间向前移动到最接近的存在时间 
- ‘shift_backward’ 将不存在的时间向后移动到最接近的存在时间 
- ‘NaT’ 将返回不存在时间的 NaT 
- timedelta 对象会将不存在的时间移动 timedelta 
- 如果时间不存在,‘raise’ 将引发 NonExistentTimeError。 
 
 
- DatetimeIndex、TimedeltaIndex 或 Series
- DatetimeIndex 或 TimedeltaIndex 具有相同类型的索引,或者 Series 具有相同索引的 Series。 
 
- 如果无法转换 - freq,则出现 ValueError。
 
 - 参数:- 返回:- 抛出:- 注意:- 如果时间戳具有时区,则 floor 将相对于本地 (“wall”) 时间进行,并重新本地化到同一时区。在夏令时附近铺设 floor 时,使用 - nonexistent和- ambiguous来控制重新定位行为。- 例子:- 日期时间索引 - >>> rng = pd.date_range('1/1/2018 11:59:00', periods=3, freq='min') >>> rng DatetimeIndex(['2018-01-01 11:59:00', '2018-01-01 12:00:00', '2018-01-01 12:01:00'], dtype='datetime64[ns]', freq='T') >>> rng.floor('H') DatetimeIndex(['2018-01-01 11:00:00', '2018-01-01 12:00:00', '2018-01-01 12:00:00'], dtype='datetime64[ns]', freq=None)- Series - >>> pd.Series(rng).dt.floor("H") 0 2018-01-01 11:00:00 1 2018-01-01 12:00:00 2 2018-01-01 12:00:00 dtype:datetime64[ns]- 在夏令时转换附近四舍五入时,使用 - ambiguous或- nonexistent来控制如何重新定位时间戳。- >>> rng_tz = pd.DatetimeIndex(["2021-10-31 03:30:00"], tz="Europe/Amsterdam")- >>> rng_tz.floor("2H", ambiguous=False) DatetimeIndex(['2021-10-31 02:00:00+01:00'], dtype='datetime64[ns, Europe/Amsterdam]', freq=None)- >>> rng_tz.floor("2H", ambiguous=True) DatetimeIndex(['2021-10-31 02:00:00+02:00'], dtype='datetime64[ns, Europe/Amsterdam]', freq=None)
相关用法
- Python pandas.DatetimeIndex.day用法及代码示例
- Python pandas.DatetimeIndex.dayofweek用法及代码示例
- Python pandas.DatetimeIndex.to_frame用法及代码示例
- Python pandas.DatetimeIndex.normalize用法及代码示例
- Python pandas.DatetimeIndex.is_year_start用法及代码示例
- Python pandas.DatetimeIndex.tz_convert用法及代码示例
- Python pandas.DatetimeIndex.is_quarter_start用法及代码示例
- Python pandas.DatetimeIndex.month用法及代码示例
- Python pandas.DatetimeIndex.is_leap_year用法及代码示例
- Python pandas.DatetimeIndex.round用法及代码示例
- Python pandas.DatetimeIndex.month_name用法及代码示例
- Python pandas.DatetimeIndex.is_year_end用法及代码示例
- Python pandas.DatetimeIndex.year用法及代码示例
- Python pandas.DatetimeIndex.nanosecond用法及代码示例
- Python pandas.DatetimeIndex.is_month_start用法及代码示例
- Python pandas.DatetimeIndex.hour用法及代码示例
- Python pandas.DatetimeIndex.day_name用法及代码示例
- Python pandas.DatetimeIndex.tz_localize用法及代码示例
- Python pandas.DatetimeIndex.microsecond用法及代码示例
- Python pandas.DatetimeIndex.weekday用法及代码示例
注:本文由纯净天空筛选整理自pandas.pydata.org大神的英文原创作品 pandas.DatetimeIndex.floor。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
