Python Pandas tseries.offsets.DateOffset.rule_code

Python Pandas tseries.offsets.DateOffset.rule_code

Dateoffsets是一种标准的日期增量,用于Pandas中的日期范围。在我们传入的关键字args方面,它的工作方式与relativedelta完全一样。DateOffsets的工作原理如下,每个偏移量指定一组符合DateOffset的日期。例如,Bday定义这个集合为工作日(M-F)的日期集合。DateOffsets可以被创建,以将日期向前移动一个给定数量的有效日期。例如,Bday(2)可以被添加到一个日期,使其向前移动两个工作日。如果日期不是从一个有效的日期开始,首先它被移到一个有效的日期,然后创建偏移。Pandas tseries.offsets.DateOffset.rule_code属性返回应用于给定DateOffset对象的规则代码。例如,BMonthEnd的rule_code是’BM’。

语法: pandas.tseries.offsets.DateOffset.rule_code

参数 : None

返回 : rule_code

例子#1:使用pandas.tseries.offsets.DateOffset.rule_code属性来返回应用于给定DateOffset对象的rule_code。

# 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.rule_code

Python Pandas tseries.offsets.DateOffset.rule_code

现在我们将在给定的时间戳对象上添加dateoffset,以增加日期时间值。我们还将返回应用于给定DateOffset对象的rule_code。

# Adding the dateoffset to the given timestamp
new_timestamp = ts + do
 
# Print the updated timestamp
print(new_timestamp)
 
# Now we will print the rule_code applied
# on the given DateOffset object
print(do.rule_code)
Python

输出 :

Python Pandas tseries.offsets.DateOffset.rule_code

Python Pandas tseries.offsets.DateOffset.rule_code

正如我们在输出中看到的,该属性已经成功返回应用于给定Dateoffset对象的规则代码。

例子#2:使用pandas.tseries.offsets.DateOffset.rule_code属性来返回应用在给定的DateOffset对象上的规则_code。

# 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)
Python

输出 :

Python Pandas tseries.offsets.DateOffset.rule_code

Python Pandas tseries.offsets.DateOffset.rule_code

现在我们将在给定的时间戳对象上添加dateoffset,以增加日期时间值。我们还将返回应用于给定DateOffset对象的rule_code。

# Adding the dateoffset to the given timestamp
new_timestamp = ts + do
 
# Print the updated timestamp
print(new_timestamp)
 
# Now we will print the rule_code applied
# on the given DateOffset object
print(do.rule_code)
Python

输出 :

Python Pandas tseries.offsets.DateOffset.rule_code

Python Pandas tseries.offsets.DateOffset.rule_code

我们可以在输出中看到,该属性已经成功地返回了应用在给定Dateoffset对象上的规则_代码。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册