📜  Python| Pandas PeriodIndex.hour

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

Python| Pandas PeriodIndex.hour

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

Pandas PeriodIndex.hour属性返回给定 PeriodIndex 对象的周期小时数。

示例 #1:使用PeriodIndex.hour属性查找给定 PeriodIndex 对象的时段的小时值。

# importing pandas as pd
import pandas as pd
  
# Create the PeriodIndex object
pidx = pd.PeriodIndex(start ='2005-12-21 08:45 ', 
              end ='2005-12-21 11:55', freq ='H')
  
# Print the PeriodIndex object
print(pidx)

输出 :

现在我们将使用PeriodIndex.hour属性来查找给定对象中周期的小时。

# return the hour value
pidx.hour

输出 :

正如我们在输出中看到的, PeriodIndex.hour属性返回了一个索引对象,其中包含给定 PeriodIndex 对象的每个元素的小时值。示例 #2:使用PeriodIndex.hour属性来查找给定 PeriodIndex 对象的周期小时。

# importing pandas as pd
import pandas as pd
  
# Create the PeriodIndex object
pidx = pd.PeriodIndex(start ='2011-02-1', 
           end ='2011-02-14', freq ='D')
  
# Print the PeriodIndex object
print(pidx)

输出 :

现在我们将使用PeriodIndex.hour属性来查找给定对象中周期的小时值。

# return the hour value
pidx.hour

输出 :

正如我们在输出中看到的, PeriodIndex.hour属性返回了一个索引对象,其中包含给定 PeriodIndex 对象的每个元素的小时值。正如我们所看到的,我们应用了每日频率的 pidx 对象。因此,小时值未设置,因此该函数为所有元素返回 0。