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


Python Pandas Period.weekofyear用法及代碼示例

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

Pandas Period.weekofyear屬性返回一個整數值,該整數值是給定Period對象的一年中的第幾周。

用法: Period.weekofyear

參數:沒有

返回:一年中的第幾周

範例1:采用Period.weekofyear 屬性以查找給定Period對象的星期數。

# importing pandas as pd 
import pandas as pd 
  
# Create the Period object 
prd = pd.Period(freq ='S', year = 2000, month = 2,  
                  day = 21, hour = 8, minute = 21) 
  
# Print the Period object 
print(prd)

輸出:

現在我們將使用Period.weekofyear屬性以查找一年中的第幾周

# return week number for the year 
prd.weekofyear

輸出:

正如我們在輸出中看到的,Period.weekofyear 屬性已返回8,指示prd對象中的時間段位於一年中的第8周。

範例2:采用Period.weekofyear屬性以查找給定Period對象的星期數。

# importing pandas as pd 
import pandas as pd 
  
# Create the Period object 
prd = pd.Period(freq ='T', year = 2006, month = 10, 
                            hour = 15, minute = 49) 
  
# Print the Period object 
print(prd)

輸出:


現在我們將使用Period.weekofyear屬性以查找一年中的第幾周

# return week number for the year 
prd.weekofyear

輸出:

正如我們在輸出中看到的,Period.weekofyear 屬性已返回39,指示prd對象中的時間段位於一年的第39周。



相關用法


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