Python Pandas PeriodIndex.is_leap_year
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas PeriodIndex.is_leap_year属性返回一个布尔值数组,对应于PeriodIndex对象中的每个元素。如果给定的年份是闰年,则返回True,如果不是闰年,则返回False。
语法 :
PeriodIndex.is_leap_year
参数:无
返回 : 布尔值的数组
例子#1:使用PeriodIndex.is_leap_year属性来检查给定PeriodIndex对象中的每个元素,是否是闰年。
# importing pandas as pd
import pandas as pd
# Create the PeriodIndex object
pidx = pd.PeriodIndex(start ='2003-12-21 08:45 ',
end ='2009-12-21 11:55', freq ='Y')
# Print the PeriodIndex object
print(pidx)
输出 :
现在我们将使用PeriodIndex.is_leap_year属性来检查给定年份是否是闰年。
# check for leap year
pidx.is_leap_year
输出 :
正如我们在输出中看到的,PeriodIndex.is_leap_year属性返回一个包含布尔值的数组。True表示给定的年份是闰年,False表示给定的年份不是闰年。
例子#2:使用PeriodIndex.is_leap_year属性来检查给定的PeriodIndex对象中的每个元素,是否是闰年。
# importing pandas as pd
import pandas as pd
# Create the PeriodIndex object
pidx = pd.PeriodIndex(start ='2016-02-1',
end ='2016-02-06', freq ='D')
# Print the PeriodIndex object
print(pidx)
输出 :
现在我们将使用PeriodIndex.is_leap_year属性来检查给定年份是否是闰年。
# check for leap year
pidx.is_leap_year
输出 :
正如我们在输出中看到的,PeriodIndex.is_leap_year属性返回一个包含布尔值的数组。True表示给定的年份是闰年,False表示给定的年份不是闰年。