Dateoffsets是用于Pandas中日期范围的标准日期增量。就我们传入的关键字args而言,它的工作方式与relativedelta完全相同。DateOffets的工作方式如下,每个偏移量指定一组符合DateOffset的日期。例如,“ Bday”将此集合定义为工作日的日期集合(M-F)。
可以创建DateOffsets以将日期向前移动给定数量的有效日期。例如,可以将Bday(2)添加到日期以将其向前移动两个工作日。如果日期不是从有效日期开始,则首先将其移动到有效日期,然后创建偏移量。
Pandas tseries.offsets.BusinessHour.copy()函数用于创建给定偏移对象的副本。
用法: pandas.tseries.offsets.BusinessHour.copy()
参数:没有
返回:复制
范例1:采用pandas.tseries.offsets.BusinessHour.copy()函数创建给定偏移对象的副本。
# 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)
输出:
现在,我们将营业时间偏移量添加到给定的timestamp对象,以增加datetime值。我们还将创建给定偏移对象的副本。
# Adding the Business hour offset to the given timestamp
new_timestamp = ts + bh
# Print the updated timestamp
print(new_timestamp)
# create a copy
bh_copy = bh.copy()
# Check if both objects are same
print(bh is bh_copy)
输出:
从输出中可以看到,我们已经成功创建了一个偏移并将其添加到给定的时间戳中。我们还测试了两个副本是否相同。
范例2:采用pandas.tseries.offsets.BusinessHour.copy()函数创建给定偏移对象的副本。
# 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)
输出:
现在,我们将营业时间偏移量添加到给定的timestamp对象,以增加datetime值。我们还将创建给定偏移对象的副本。
# Adding the Business hour offset to the given timestamp
new_timestamp = ts + bh
# Print the updated timestamp
print(new_timestamp)
# create a copy
bh_copy = bh.copy()
# Check if both objects are same
print(bh is bh_copy)
输出:
从输出中可以看到,我们已经成功创建了一个偏移并将其添加到给定的时间戳中。我们还测试了两个副本是否相同。