【问题标题】:Create a blank date in python在python中创建一个空白日期
【发布时间】:2020-05-22 07:49:02
【问题描述】:

我想在数据框中添加格式为“%Y-%m-%d”的空白日期列。我试过datetime.datetime.strptime('0000-00-00',"%Y-%m-%d")

但我收到一个错误ValueError: time data '0000-00-00' does not match format '%Y-%m-%d'

如何创建格式为“%Y-%m-%d”的空白日期列?

在 R 以下的作品中。

df$date =""
class(df$date) = "Date" 

如何在 Python 中实现这一点?

谢谢。

【问题讨论】:

  • 参数must fit 的范围如下:1
  • python中的日期时间限制在1677-09-21 00:12:442262-04-11 23:47:16

标签: python date


【解决方案1】:

我认为 datetime 模块不可能。您可以去的最古老的答案在这里: What is the oldest time that can be represented in Python?

datetime.MINYEAR

    The smallest year number allowed in a date or datetime object. MINYEAR is 1.

datetime.MAXYEAR

    The largest year number allowed in a date or datetime object. MAXYEAR is 9999.

来源:datetime documentation

【讨论】:

  • 那么,这是否意味着我们不能在 pyhton 中发起空白日期?
  • 没有。因为没有第0个月。它不存在。此外,没有日期为 0 的月份。不仅在 python 中,这种格式的日期不能存在于任何语言中,除非 0 对应于一年中的第一个月或一个月的第一天,这通常不太可能。跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-13
  • 2018-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多