Python Pandas DatetimeIndex.is_leap_year

Python Pandas DatetimeIndex.is_leap_year

Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。

Pandas DatetimeIndex.is_leap_year属性返回一个布尔指标,说明该日期是否属于闰年。闰年是指有366天(而不是365天)的年份,包括2月29日这个闰日。闰年是4的倍数的年份,但可以被100除以的年份除外,但不能被400除以。

语法: DatetimeIndex.is_leap_year

返回:包含逻辑值的numpy数组。

例子#1:使用DatetimeIndex.is_leap_year属性来检查DatetimeIndex对象中的日期是否属于闰年。

# importing pandas as pd
import pandas as pd
  
# Create the DatetimeIndex
didx = pd.DatetimeIndex(['2014-01-01', '2008-12-31', '2017-03-31', '2000-12-31'])
  
# Print the DatetimeIndex
print(didx)
Python

输出 :
Python Pandas DatetimeIndex.is_leap_year

现在,我们要找出给定的DatetimeIndex对象中包含的日期是否属于闰年。

# find if the dates belong to leap year
didx.is_leap_year
Python

输出 :
Python Pandas DatetimeIndex.is_leap_year
正如我们在输出中所看到的,该函数返回了一个包含DatetimeIndex对象的每个条目的逻辑值的numpy数组。真值表示对应的日期属于闰年,假值表示对应的日期不属于闰年。

例子2:使用DatetimeIndex.is_leap_year属性来检查DatetimeIndex对象中的日期是否属于闰年。

# importing pandas as pd
import pandas as pd
  
# Create the DatetimeIndex
didx = pd.date_range("2008-12-30", periods = 5, freq ='Q')
  
# Print the DatetimeIndex
print(didx)
Python

输出 :
Python Pandas DatetimeIndex.is_leap_year

现在,我们要找到给定的DatetimeIndex对象中包含的日期是否属于闰年。

# find if the dates belong to leap year
didx.is_leap_year
Python

输出 :
Python Pandas DatetimeIndex.is_leap_year
正如我们在输出中所看到的,该函数返回了一个包含DatetimeIndex对象的每个条目的逻辑值的numpy数组。真值表示对应的日期属于闰年,假值表示对应的日期不属于闰年。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册