Python Pandas DatetimeIndex.quarter
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas DatetimeIndex.quarter属性输出DatetimeIndex对象中每个条目的日期的季度。
语法: DatetimeIndex.quarter
返回:索引对象
例子#1:使用DatetimeIndex.quarter属性来查找DatetimeIndex对象中每个条目的日期的季度。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here 'M' represents Monthly frequency
didx = pd.DatetimeIndex(start ='2014-08-01 10:05:45', freq ='M',
periods = 5, tz ='Asia/Calcutta')
# Print the DatetimeIndex
print(didx)
输出 :
现在我们要为DatetimeIndex对象中的每个条目找到日期的四分之一。
# find the quarter of date
didx.quarter
输出 :
正如我们在输出中所看到的,该函数返回了一个Index对象,其中包含了DatetimeIndex对象的每个条目的日期的四分之一值。
示例#2:使用DatetimeIndex.quarter属性来查找DatetimeIndex对象中每个条目的日期的季度。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here 'Q' represents Quarterly frequency
didx = pd.DatetimeIndex(start ='2000-01-10 06:30', freq ='Q',
periods = 5, tz ='Asia/Calcutta')
# Print the DatetimeIndex
print(didx)
输出 :
现在我们要为DatetimeIndex对象中的每个条目找到日期的四分之一。
# find the quarter of date
didx.quarter
输出 :
正如我们在输出中所看到的,该函数返回了一个Index对象,其中包含了DatetimeIndex对象的每个条目的日期的四分之一值。