Python Pandas tseries.offsets.DateOffset.isAnchored

Python Pandas tseries.offsets.DateOffset.isAnchored

Dateoffsets是一种标准的日期增量,用于Pandas中的日期范围。就我们传入的关键字args而言,它的工作方式与relativedelta完全一样。DateOffets的工作原理如下,每个偏移量指定一组符合DateOffset的日期。例如,Bday定义这个集合为工作日(M-F)的日期集合。

DateOffsets可以被创建,以将日期向前移动一个给定的有效日期的数量。例如,Bday(2)可以被添加到一个日期,使其向前移动两个工作日。如果该日期不是从一个有效的日期开始,首先它被移到一个有效的日期,然后创建偏移。

Pandas tseries.offsets.DateOffset.isAnchored()函数返回一个布尔值。如果给定的DateOffset是锚定的,它返回True,否则它返回False。

语法: pandas.tseries.offsets.DateOffset.isAnchored()

参数:

返回 : 布尔值

例子#1:使用pandas.tseries.offsets.DateOffset.isAnchored()函数来检查给定的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)
Python

输出 :

Python Pandas tseries.offsets.DateOffset.isAnchored

Python Pandas tseries.offsets.DateOffset.isAnchored

现在,我们将在给定的时间戳对象上添加Dateoffset,以增加数据时间值。我们还将检查给定的DateOffset是否是锚定的。

# Adding the dateoffset to the given timestamp
new_timestamp = ts + do
  
# Print the updated timestamp
print(new_timestamp)
  
# Now we will check if the given DateOffset
# is anchored or not.
print(do.isAnchored())
Python

输出 :

Python Pandas tseries.offsets.DateOffset.isAnchored

Python Pandas tseries.offsets.DateOffset.isAnchored

正如我们在输出中看到的,该函数返回了False,表明给定的DateOffset没有被锚定。

例子#2:使用pandas.tseries.offsets.DateOffset.isAnchored()函数来检查给定的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 = 'W-SUN')
  
# Print the Timestamp
print(ts)
  
# Print the DateOffset
print(do)
Python

输出 :

Python Pandas tseries.offsets.DateOffset.isAnchored

Python Pandas tseries.offsets.DateOffset.isAnchored

现在,我们将在给定的时间戳对象上添加Dateoffset,以增加数据时间值。我们还将检查给定的DateOffset是否是锚定的。

# Adding the dateoffset to the given timestamp
new_timestamp = ts + do
  
# Print the updated timestamp
print(new_timestamp)
  
# Now we will check if the given DateOffset
# is anchored or not.
print(do.isAnchored())
Python

输出 :

Python Pandas tseries.offsets.DateOffset.isAnchored

Python Pandas tseries.offsets.DateOffset.isAnchored

正如我们在输出中看到的,该函数返回了True,表明给定的DateOffset是锚定的。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册