【问题标题】:Is there a way I can filter out all those columns which has dates stored under them - Jupyter(Python)?有没有一种方法可以过滤掉所有存储日期的列 - Jupyter(Python)?
【发布时间】:2020-07-20 18:40:53
【问题描述】:

我需要一个程序来搜索所有在其下存储日期的列。由于 .dtypes 会将日期、字符串和许多其他字段识别为 Python 中的对象,因此我需要找到一种方法,以便我的程序仅定位具有有效日期的此类列。我查看了其他答案,但他们大多展示了如何将特定数据类型转换为日期格式,这不是我想要的。

【问题讨论】:

    标签: python date types jupyter-notebook date-format


    【解决方案1】:

    我不知道您使用哪种日期格式。 例如你可以使用时间库

    import time
    
    
    def is_it_date(date):
        try:
            time.strptime(date, '%m/%d/%Y')
            print('yes it is a date')
        except ValueError:
            print('it is doesn`t date')
    
    is_it_date('02/03/2020')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-22
      • 1970-01-01
      • 1970-01-01
      • 2019-11-04
      • 2013-05-15
      • 2023-02-04
      • 2016-05-11
      • 1970-01-01
      相关资源
      最近更新 更多