Python Pandas tseries.offsets.CustomBusinessDay.name

Python Pandas tseries.offsets.CustomBusinessDay.name

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

语法: pandas.tseries.offsets.CustomBusinessDay.name

参数 : None

返回 :应用的频率名称为字符串。

例子#1:使用pandas.tseries.offsets.CustomBusinessDay.name属性,以字符串形式返回应用于给定偏移对象的频率名称。

# importing pandas as pd
import pandas as pd
 
# Creating Timestamp
ts = pd.Timestamp('2019-4-23 11:15:00')
 
# Create an offset
cbd = pd.tseries.offsets.CustomBusinessDay(weekmask = 'Mon Tue Wed')
 
# Print the Timestamp
print(ts)
 
# Print the Offset
print(cbd)
Python

输出 :

Python Pandas tseries.offsets.CustomBusinessDay.name

Python Pandas tseries.offsets.CustomBusinessDay.name

现在我们将把偏移量添加到给定的时间戳对象中,以增加数据时间的值。我们还将把应用在给定偏移量对象上的频率名称打印成一个字符串。

# Adding the offset to the given timestamp
new_timestamp = ts + cbd
 
# Print the updated timestamp
print(new_timestamp)
 
# find the name of the frequency applied on
# the given offset
result = cbd.name
 
# print the result
print(result)
Python

输出 :

Python Pandas tseries.offsets.CustomBusinessDay.name

Python Pandas tseries.offsets.CustomBusinessDay.name

正如我们在输出中看到的,我们已经成功地创建了一个偏移量并将其添加到给定的时间戳中。我们还把应用在给定偏移量对象上的频率名称打印成一个字符串。

例子#2:使用pandas.tseries.offsets.CustomBusinessDay.name属性来返回应用在给定偏移对象上的频率的名称,作为一个字符串。

# importing pandas as pd
import pandas as pd
 
# Creating Timestamp
ts = pd.Timestamp('2019-4-23 11:15:00')
 
# Create an offset
cbd = pd.tseries.offsets.CustomBusinessDay(n = 3, weekmask = 'Mon Tue Wed Thu')
 
# Print the Timestamp
print(ts)
 
# Print the Offset
print(cbd)
Python

输出 :

Python Pandas tseries.offsets.CustomBusinessDay.name

Python Pandas tseries.offsets.CustomBusinessDay.name

现在我们将把偏移量添加到给定的时间戳对象中,以增加日期时间值。我们还将把应用在给定偏移量对象上的频率名称打印成一个字符串。

# Adding the offset to the given timestamp
new_timestamp = ts + cbd
 
# Print the updated timestamp
print(new_timestamp)
 
# find the name of the frequency applied on
# the given offset
result = cbd.name
 
# print the result
print(result)
Python

输出 :

Python Pandas tseries.offsets.CustomBusinessDay.name

Python Pandas tseries.offsets.CustomBusinessDay.name

正如我们在输出中看到的,我们已经成功地创建了一个偏移量并将其添加到给定的时间戳中。我们还把应用在给定偏移量对象上的频率名称打印成一个字符串。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册