Python Pandas - 指示 PeriodIndex 对象中的日期是否属于闰年
要指示PeriodIndex对象中的日期是否属于闰年,请使用periodIndex.is_leap_year属性。
首先,导入所需的库-
import pandas as pd
创建一个PeriodIndex对象-
periodIndex = pd.PeriodIndex(['2021-09-25 07:50:35', '2019-10-30 04:35:45', '2016-07-15 02:25:15', '2020-06-25 09:20:55'], freq="T")
显示PeriodIndex对象-
print("PeriodIndex...\n", periodIndex)检查日期是否为闰年-
print("\nWhether the date is a leap year?\n", periodIndex.is_leap_year)示例
以下是代码-
import pandas as pd
#CreateaPeriodIndexobject
#PeriodIndexisanimmutablendarrayholdingordinalvaluesindicatingregularperiodsintime
# We have set the frequency using the "freq" parameter
periodIndex = pd.PeriodIndex(['2021-09-25 07:50:35', '2019-10-30 04:35:45',
'2016-07-15 02:25:15', '2020-06-25 09:20:55'], freq="T")
#DisplayPeriodIndexobject
print("PeriodIndex...\n", periodIndex)
#DisplayPeriodIndexfrequency
print("\nPeriodIndex frequency object...\n", periodIndex.freq)
#DisplayPeriodIndexfrequency as string
print("\nPeriodIndex frequency object as a string...\n", periodIndex.freqstr)
#Checkwhetherthedateisaleapyear
print("\nWhether the date is a leap year?\n", periodIndex.is_leap_year)输出结果这将产生以下代码-
PeriodIndex... PeriodIndex(['2021-09-25 07:50', '2019-10-30 04:35', '2016-07-15 02:25','2020-06-25 09:20'], dtype='period[T]') PeriodIndex frequency object... <Minute> PeriodIndex frequency object as a string... T Whether the date is a leap year? [False False True True]
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短