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


Python Pandas Timestamp.dayofyear用法及代碼示例

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

Pandas Timestamp.dayofyear屬性返回給定Timestamp對象的日期。這些天的編號從1到365。其中1是一年的第一天,而365是一年的最後一天。

用法: Timestamp.dayofyear

參數:沒有

返回:一年中的一天

範例1:采用Timestamp.dayofyear屬性以在給定的Timestamp對象中查找一年中的哪一天。

# importing pandas as pd 
import pandas as pd 
  
# Create the Timestamp object 
ts = pd.Timestamp(2017, 1, 15, 12) 
  
# Print the Timestamp object 
print(ts)

輸出:

現在我們將使用Timestamp.dayofyear屬性以在給定的Timestamp對象中找出一年中的哪一天。

# return day of the year 
ts.dayofyear

輸出:

正如我們在輸出中看到的,Timestamp.dayofyear屬性已返回15,表示這是給定Timestamp對象中的一年的第15天。

範例2:采用Timestamp.dayofyear屬性以在給定的Timestamp對象中查找一年中的哪一天。

# importing pandas as pd 
import pandas as pd 
  
# Create the Timestamp object 
ts = pd.Timestamp(year = 2009, month = 10,  
         day = 21, tz = 'Europe/Berlin') 
  
# Print the Timestamp object 
print(ts)

輸出:


現在我們將使用Timestamp.dayofyear屬性以在給定的Timestamp對象中找出一年中的哪一天。

# return day of the year 
ts.dayofyear

輸出:

正如我們在輸出中看到的,Timestamp.dayofyear屬性已返回294,指示它是給定Timestamp對象中的第294天。



相關用法


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