Python Pandas tseries.offsets.DateOffset.name

Python Pandas tseries.offsets.DateOffset.name

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

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

Pandas tseries.offsets.DateOffset.name属性允许你在函数中使用偏移量来简化,而不是导入和初始化这个类。它还返回应用于偏移对象的频率名称。

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

参数:

返回:名称

例子#1:使用pandas.tseries.offsets.DateOffset.name属性来返回应用于给定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.name

Python Pandas tseries.offsets.DateOffset.name

现在我们将在给定的时间戳对象上添加dateoffset,以便从给定的Date向前滚动日期。同时返回应用在给定DateOffset对象上的频率名称。

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

输出 :

Python Pandas tseries.offsets.DateOffset.name

Python Pandas tseries.offsets.DateOffset.name

正如我们在输出中看到的,该属性已经成功地返回了应用于给定Dateoffset对象的频率名称。

例子#2:使用pandas.tseries.offsets.DateOffset.name属性来返回应用于给定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)
Python

输出 :

Python Pandas tseries.offsets.DateOffset.name

Python Pandas tseries.offsets.DateOffset.name

现在我们将在给定的时间戳对象上添加dateoffset,以便从给定的Date向前滚动日期。同时返回应用在给定DateOffset对象上的频率名称。

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

输出 :

Python Pandas tseries.offsets.DateOffset.name

Python Pandas tseries.offsets.DateOffset.name

正如我们在输出中看到的,该属性已经成功地返回了应用于给定Dateoffset对象的频率名称。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册