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


Python Pandas DatetimeIndex.freqstr用法及代碼示例

Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。

Pandas DatetimeIndex.freqstr如果在DatetimeIndex對象中設置了頻率屬性,則該屬性以字符串形式返回。如果未設置頻率,則返回無。

用法: DatetimeIndex.freqstr

返回:頻率對象作為字符串

範例1:采用DatetimeIndex.freqstr屬性以將頻率對象作為字符串返回給定的DatetimeIndex對象。

# importing pandas as pd 
import pandas as pd 
  
# Create the DatetimeIndex 
# Here 'BQ' represents Business quarter frequency 
didx = pd.DatetimeIndex(start ='2014-08-01 10:05:45', freq ='BQ', 
                              periods = 5, tz ='Asia/Calcutta') 
  
# Print the DatetimeIndex 
print(didx)

輸出:

現在,我們要查找給定DatetimeIndex對象的頻率字符串值。

# find the value of frequency object as string 
didx.freqstr

輸出:

正如我們在輸出中看到的,該函數已將頻率對象作為字符串返回給定的DatetimeIndex對象。 “ BQ”代表業務季度,“ DEC”表示從12月開始。

範例2:采用DatetimeIndex.freqstr屬性以找到頻率對象作為給定DatetimeIndex對象的字符串。

# importing pandas as pd 
import pandas as pd 
  
# Create the DatetimeIndex 
# Here 'CBMS' represents custom business month start frequency 
didx = pd.DatetimeIndex(start ='2000-01-10 06:30', freq ='CBMS', 
                              periods = 5, tz ='Asia/Calcutta') 
  
# Print the DatetimeIndex 
print(didx)

輸出:

現在,我們要查找給定DatetimeIndex對象的頻率字符串值。

# find the value of frequency object as string 
didx.freqstr

輸出:

從輸出中可以看到,該函數已將頻率對象作為字符串返回給定的DatetimeIndex對象。 didx DatetimeIndex對象具有自定義營業月開始頻率。



相關用法


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