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天。
极客教程