Python Pandas tseries.offsets.DateOffset.copy
Dateoffsets是一种标准的日期增量,用于Pandas中的日期范围。就我们传入的关键字args而言,它的工作方式与relativedelta完全一样。DateOffets的工作原理如下,每个偏移量指定一组符合DateOffset的日期。例如,Bday定义这个集合为工作日(M-F)的日期集合。
DateOffsets可以被创建,以将日期向前移动一个给定的有效日期的数量。例如,Bday(2)可以被添加到一个日期,使其向前移动两个工作日。如果该日期不是从一个有效的日期开始,首先它被移到一个有效的日期,然后创建偏移。
Pandas tseries.offsets.DateOffset.copy()函数返回给定DateOffset对象的一个副本。
语法: pandas.tseries.offsets.DateOffset.copy()
参数:无
返回:给定对象的副本。
例子#1:使用pandas.tseries.offsets.DateOffset.copy()函数来返回给定DateOffset对象的副本。
# importing pandas as pd
import pandas as pd
# importing the to_offset function
from pandas.tseries.frequencies import to_offset
# Creating Timestamp
ts = pd.Timestamp('2019-10-10 07:15:11')
# Create the DateOffset of 2 day
do = to_offset(freq = '2D')
# 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)
# Now we will create a copy of the given
# DateOffset object.
do_copy = do.copy()
# Check if the two objects are same or not
print(do_copy is do)
输出 :
正如我们在输出中看到的,该函数已经成功地创建了一个给定的Dateoffset对象的副本。假的表示这两个对象不一样。
例子#2:使用pandas.tseries.offsets.DateOffset.copy()函数来返回给定DateOffset对象的副本。
# importing pandas as pd
import pandas as pd
# importing the to_offset function
from pandas.tseries.frequencies import to_offset
# Creating Timestamp
ts = pd.Timestamp('2019-10-10 07:15:11')
# Create the DateOffset
do = to_offset(freq = '10D2H')
# 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)
# Now we will create a copy of the given
# DateOffset object.
do_copy = do.copy()
# Check if the two objects are same or not
print(do_copy is do)
输出 :
正如我们在输出中看到的,该函数已经成功地创建了一个给定的Dateoffset对象的副本。假的表示这两个对象不一样。