Python Pandas PeriodIndex.hour
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas PeriodIndex.hour属性返回给定PeriodIndex对象的周期的小时数。
语法 :
PeriodIndex.hour
参数:无
返回:包含小时值的索引对象。
示例#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。