Python Pandas Period.weekofyear

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)

输出 :

Python Pandas Period.weekofyear

现在,我们将使用Period.weekofyear属性来查找当年的周数。

# return week number for the year
prd.weekofyear

输出 :

Python Pandas Period.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)

输出 :

Python Pandas Period.weekofyear

现在,我们将使用Period.weekofyear属性来查找当年的周数。

# return week number for the year
prd.weekofyear

输出 :

Python Pandas Period.weekofyear

正如我们在输出中看到的,Period.weekofyear属性返回39,表明prd对象中的周期位于一年中的第39周。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程