Python Pandas PeriodIndex.week
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas PeriodIndex.week属性返回一个索引对象,其中包含给定PeriodIndex对象的每个周期元素的星期序数值。
语法 : PeriodIndex.week
参数:无
返回:索引对象
例子#1:使用PeriodIndex.week属性来找出包含在给定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.week属性来找出给定的PeriodIndex对象在一年中的周的序数值。
# return the week's ordinal value
pidx.week
输出 :

正如我们在输出中看到的,PeriodIndex.week属性已经返回了一个Index对象,其中包含了给定PeriodIndex对象中包含的每个周期元素的周的序数值。
例子2:使用PeriodIndex.week属性来找出包含在给定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.week属性来找出给定的PeriodIndex对象在一年中的星期序数。
# return the week's ordinal value
pidx.week
输出 :

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