📜  Python| Pandas PeriodIndex.weekday

📅  最后修改于: 2022-05-13 01:55:01.282000             🧑  作者: Mango

Python| Pandas PeriodIndex.weekday

Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。

Pandas PeriodIndex.weekday属性返回一个 Index 对象,其中包含给定 PeriodIndex 对象中每个周期元素的星期一 = 0 到星期日 = 6 的星期几。

示例 #1:使用PeriodIndex.weekday属性找出给定 PeriodIndex 对象中每个 period 元素的星期几。

# 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.weekday属性来查找 pidx 对象中每个 period 元素的星期几。

# return the day of the week
pidx.weekday

输出 :

正如我们在输出中看到的, PeriodIndex.weekday属性返回了一个 Index 对象,其中包含给定 PeriodIndex 对象中包含的每个 period 元素的星期几。示例 #2:使用PeriodIndex.weekday属性找出给定 PeriodIndex 对象中每个 period 元素的星期几。

# 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.weekday属性来查找 pidx 对象中每个 period 元素的星期几。

# return the day of the week
pidx.weekday

输出 :

正如我们在输出中看到的, PeriodIndex.weekday属性返回了一个 Index 对象,其中包含给定 PeriodIndex 对象中包含的每个 period 元素的星期几。