Python Pandas tseries.offsets.DateOffset.normalize
Dateoffsets是一种标准的日期增量,用于Pandas中的日期范围。在我们传入的关键字args方面,它的工作方式与relativedelta完全一样。DateOffsets的工作原理如下,每个偏移量指定一组符合DateOffset的日期。例如,Bday定义这个集合为工作日(M-F)的日期集合。DateOffsets可以被创建,以将日期向前移动一个给定的有效日期数量。例如,Bday(2)可以被添加到日期中,使其向前移动两个工作日。如果日期不是从一个有效的日期开始,首先它被移到一个有效的日期,然后创建偏移。Pandas tseries.offsets.DateOffset.normalize属性返回布尔值。当DateOffset值被规范化时,它返回True,否则它返回False。注:归一化意味着将DateOffset加法的结果向下舍入到前一个午夜。
语法: pandas.tseries.offsets.DateOffset.normalize
参数 : None
返回 : boolean
例子#1:使用pandas.tseries.offsets.DateOffset.normalize属性来检查给定的DateOffset值是否已经被规范化。
# importing pandas as pd
import pandas as pd
# Creating Timestamp
ts = pd.Timestamp('2019-10-10 07:15:11')
# Create the DateOffset
do = pd.tseries.offsets.DateOffset(n = 2)
# Print the Timestamp
print(ts)
# Print the DateOffset
print(do)
输出 :
现在我们将把Dateoffset添加到给定的时间戳对象中,使其增量。我们还将检查DateOffset是否已经被规范化。
# Adding the dateoffset to the given timestamp
new_timestamp = ts + do
# Print the updated timestamp
print(new_timestamp)
# check if the DateOffset has been normalized or not
print(do.normalize)
输出 :
我们可以在输出中看到,该属性已经成功地返回了一个布尔值,表明给定的DateOffset是否被正常化了。
例子2:使用pandas.tseries.offsets.DateOffset.normalize属性来检查给定的DateOffset值是否已经被规范化。
# importing pandas as pd
import pandas as pd
# Creating Timestamp
ts = pd.Timestamp('2019-10-10 07:15:11')
# Create the DateOffset
# Also normalize it
do = pd.tseries.offsets.DateOffset(days = 10, hours = 2, normalize = True)
# Print the Timestamp
print(ts)
# Print the DateOffset
print(do)
输出 :
现在我们将把Dateoffset添加到给定的时间戳对象中,使其增量。我们还将检查DateOffset是否已被规范化。
# Adding the dateoffset to the given timestamp
new_timestamp = ts + do
# Print the updated timestamp
print(new_timestamp)
# check if the DateOffset has been normalized or not
print(do.normalize)
输出 :
我们可以在输出中看到,该属性已经成功返回了一个布尔值,表明给定的DateOffset是否已经被规范化。