pandas.DatetimeIndex.normalize#

DatetimeIndex.normalize(*args, **kwargs)[源代码]#

将时间转换为午夜。

日期-时间的时间部分被转换为午夜,即00:00:00。这在时间无关紧要的情况下很有用。长度保持不变。时区不受影响。

此方法在具有DateTime值的系列中可用 .dt 访问器,并直接在DateTime数组/索引上。

退货
Datetime数组、DatetimeIndex或系列

与原始数据相同的类型。系列将具有相同的名称和索引。DatetimeIndex将具有相同的名称。

参见

floor

将DateTime设置为指定的频率。

ceil

将日期时间设置为指定的频率。

round

将日期时间舍入为指定的频率。

示例

>>> idx = pd.date_range(start='2014-08-01 10:00', freq='H',
...                     periods=3, tz='Asia/Calcutta')
>>> idx
DatetimeIndex(['2014-08-01 10:00:00+05:30',
               '2014-08-01 11:00:00+05:30',
               '2014-08-01 12:00:00+05:30'],
                dtype='datetime64[ns, Asia/Calcutta]', freq='H')
>>> idx.normalize()
DatetimeIndex(['2014-08-01 00:00:00+05:30',
               '2014-08-01 00:00:00+05:30',
               '2014-08-01 00:00:00+05:30'],
               dtype='datetime64[ns, Asia/Calcutta]', freq=None)