Python Pandas tseries.offsets.DateOffset.kwds

Python Pandas tseries.offsets.DateOffset.kwds

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

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

参数:

返回:关键词参数

例子#1:使用pandas.tseries.offsets.DateOffset.kwds属性来返回应用于给定DateOffset对象的关键词参数。

# importing pandas as pd
import pandas as pd
 
# Creating Timestamp
ts = pd.Timestamp('2019-10-10 07:15:11')
 
# Create the DateOffset
do = pd.tseries.offsets.DateOffset(n = 2)
 
# Print the Timestamp
print(ts)
 
# Print the DateOffset
print(do)
Python

输出 :

Python Pandas tseries.offsets.DateOffset.kwds

Python Pandas tseries.offsets.DateOffset.kwds

现在我们将把dateoffset添加到给定的时间戳对象中,以创建一个与给定日期相差2天的抵消。同时返回应用在给定DateOffset对象上的关键词参数。

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

输出 :

Python Pandas tseries.offsets.DateOffset.kwds

Python Pandas tseries.offsets.DateOffset.kwds

我们可以在输出中看到,该属性已成功返回应用于给定DateOffset对象的关键词参数。由于没有应用**kwds参数,所以打印了'{}’。

例子#2:使用pandas.tseries.offsets.DateOffset.kwds属性来返回应用于给定DateOffset对象的关键词参数。

# importing pandas as pd
import pandas as pd
 
# Creating Timestamp
ts = pd.Timestamp('2019-10-10 07:15:11')
 
# Create the DateOffset
do = pd.tseries.offsets.DateOffset(days = 10, hours = 2)
 
# Print the Timestamp
print(ts)
 
# Print the DateOffset
print(do)
Python

输出 :

Python Pandas tseries.offsets.DateOffset.kwds

Python Pandas tseries.offsets.DateOffset.kwds

现在我们将把dateoffset添加到给定的时间戳对象中,以创建一个离给定日期10天和2小时的偏移。同时返回应用在给定DateOffset对象上的关键词参数。

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

输出 :

Python Pandas tseries.offsets.DateOffset.kwds

Python Pandas tseries.offsets.DateOffset.kwds

我们可以在输出中看到,该属性已经成功返回应用于给定DateOffset对象的关键词参数。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册