Python Pandas tseries.offsets.BusinessHour.isAnchored
Dateoffsets是一种标准的日期增量,用于Pandas中的日期范围。在我们传入的关键字args方面,它的工作方式与relativedelta完全一样。DateOffsets的工作原理如下,每个偏移量指定一组符合DateOffset的日期。例如,Bday定义这个集合为工作日(M-F)的日期集合。DateOffsets可以被创建,以将日期向前移动一个给定的有效日期数量。例如,Bday(2)可以被添加到一个日期,使其向前移动两个工作日。如果日期不是从一个有效的日期开始,首先它被移到一个有效的日期,然后创建偏移。Pandas tseries.offsets.BusinessHour.isAnchored()函数被用来检查给定的偏移量是否被锚定。
语法: pandas.tseries.offsets.BusinessHour.isAnchored()
参数 : None
结果 : boolean
例子#1:使用pandas.tseries.offsets.BusinessHour.isAnchored()函数来检查给定的偏移对象是否被锚定。
# importing pandas as pd
import pandas as pd
# Creating Timestamp
ts = pd.Timestamp('2019-10-10 11:15:00')
# Create an offset
bh = pd.tseries.offsets.BusinessHour(n = 5)
# Print the Timestamp
print(ts)
# Print the Offset
print(bh)
输出 :
现在我们将在给定的时间戳对象上添加营业时间的偏移,以增加数据时间值。我们还将检查给定的偏移量是否是锚定的。
# Adding the Business hour offset to the given timestamp
new_timestamp = ts + bh
# Print the updated timestamp
print(new_timestamp)
# check if the offset is
# anchored or not
result = bh.isAnchored()
# print the result
print(result)
输出 :
我们可以在输出中看到,我们已经成功创建了一个偏移量,并将其添加到给定的时间戳。该函数返回False,表明给定的偏移量没有被锚定。
例子2:使用pandas.tseries.offsets.BusinessHour.isAnchored()函数来检查给定的偏移对象是否被锚定。
# importing pandas as pd
import pandas as pd
# Creating Timestamp
ts = pd.Timestamp('2019-10-10 11:15:00')
# Create an offset
bh = pd.tseries.offsets.BusinessHour(offset = datetime.timedelta(hours = 1))
# Print the Timestamp
print(ts)
# Print the Offset
print(bh)
输出 :
现在我们将在给定的时间戳对象上添加营业时间的偏移,以增加数据时间值。我们还将检查给定的偏移量是否是锚定的。
# Adding the Business hour offset to the given timestamp
new_timestamp = ts + bh
# Print the updated timestamp
print(new_timestamp)
# check if the offset is
# anchored or not
result = bh.isAnchored()
# print the result
print(result)
输出 :
我们可以在输出中看到,我们已经成功创建了一个偏移量,并将其添加到给定的时间戳。该函数返回True,表明给定的偏移量已经被锚定。