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添加到给定的timestamp对象中,以增加datetime值。我们还将返回给定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对象的副本。False表示两个对象不相同。
范例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添加到给定的timestamp对象中,以增加datetime值。我们还将返回给定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对象的副本。False表示两个对象不相同。
相关用法
- Python pandas.map()用法及代码示例
- Python Pandas Series.str.len()用法及代码示例
- Python Pandas.factorize()用法及代码示例
- Python Pandas TimedeltaIndex.name用法及代码示例
- Python Pandas dataframe.ne()用法及代码示例
- Python Pandas Series.between()用法及代码示例
- Python Pandas DataFrame.where()用法及代码示例
- Python Pandas Series.add()用法及代码示例
- Python Pandas.pivot_table()用法及代码示例
- Python Pandas Series.mod()用法及代码示例
- Python Pandas Dataframe.at[ ]用法及代码示例
- Python Pandas Dataframe.iat[ ]用法及代码示例
- Python Pandas.pivot()用法及代码示例
- Python Pandas dataframe.mul()用法及代码示例
- Python Pandas.melt()用法及代码示例
注:本文由纯净天空筛选整理自Shubham__Ranjan大神的英文原创作品 Python | Pandas tseries.offsets.DateOffset.copy。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
