Python Pandas PeriodIndex.weekofyear
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas PeriodIndex.weekofyear属性返回一个索引对象,包含给定PeriodIndex对象的每个周期元素的星期序数值。
语法 : PeriodIndex.weekofyear
参数:无
返回:索引对象
示例#1:使用PeriodIndex.weekofyear属性来找出包含在给定PeriodIndex对象中的每个周期元素的周的序数值。
# importing pandas as pd
import pandas as pd
  
# Create the PeriodIndex object
pidx = pd.PeriodIndex(start ='2004-11-11 02:45:21 ',
               end ='2004-11-21 8:45:29', freq ='D')
  
# Print the PeriodIndex object
print(pidx)
输出 :

现在我们将使用PeriodIndex.weekofyear属性来找出给定的PeriodIndex对象在一年中的序数值。
# return the week's ordinal value in the year
pidx.weekofyear
输出 :

正如我们在输出中看到的,PeriodIndex.weekofyear属性返回了一个Index对象,其中包含了给定PeriodIndex对象中包含的每个周期元素的周的序数值。
例子2:使用PeriodIndex.weekofyear属性来找出包含在给定PeriodIndex对象中的每个周期元素的周的序数值。
# importing pandas as pd
import pandas as pd
  
# Create the PeriodIndex object
pidx = pd.PeriodIndex(start ='2016-2-12 11:12:02',
            end ='2016-09-12 11:32:12', freq ='M')
  
# Print the PeriodIndex object
print(pidx)
输出 :

现在我们将使用PeriodIndex.weekofyear属性来找出给定的PeriodIndex对象在一年中的序数值。
# return the week's ordinal value
pidx.weekofyear
输出 :

正如我们在输出中看到的,PeriodIndex.weekofyear属性返回了一个Index对象,其中包含了给定PeriodIndex对象中包含的每个周期元素的周的序数值。
 极客教程
极客教程