python中怎么判断某一年是闰年?

  统计/机器学习 时间序列 Python    浏览次数:2410        分享
0

python中怎么判断某一年是闰年?

 

小老虎   2019-04-26 16:21



   2个回答 
4

python有built-in的calendar

import calendar
calendar.isleap(2016)
SofaSofa数据科学社区DS面试题库 DS面经

Lydia   2019-04-27 00:58

2

如果年份末尾两个零,除以400;不然除以4,能被整除就是闰年。

def is_leap(year):
    return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
SofaSofa数据科学社区DS面试题库 DS面经

数据科学小K   2019-04-27 08:51



  相关讨论

python如何对日期做遍历?有没有类似range的函数?

fbprophet.Prophet里的growth='linear'和growth='logistic'有什么区别?

datetime模块里的datetime.combine什么用?

求助,按照百度的方法从日期提取年龄出现错误了

怎么在python中获取昨天的日期的字符串?

python两个日期,求间隔的天数

怎么把datetime类型转为字符串类型,但只保留日期

python中如何修改时间戳变量里的小时?

怎么判断一个时间序列是平稳的?

如何判断时间序列的周期性?

  随便看看

Random Forest可以用来做聚类?

pandas报错ValueError: Cannot convert non-finite values (NA or inf) to integer

怎么把pandas.DataFrame转成torch.tensor的格式?

怎么把pandas dataframe中的一列转成一个list?

K-means怎么选K?