當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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對象的每個條目的日期的四分之一值。



相關用法


注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas DatetimeIndex.quarter。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。