【问题标题】:Pandas returns Dec 31 as max date, not the next yearPandas 将 12 月 31 日作为最大日期返回,而不是明年
【发布时间】:2014-02-12 15:33:17
【问题描述】:

为什么此代码返回 12-31-2013 作为最大日期,而不是 1-1-2014? 与我阅读文件的方式有关吗?

import pandas as pd
df = pd.read_csv('mycsv.csv', parse_dates=True)  
print df['simpleDate'].max()

输出:2013 年 12 月 31 日

表:

simpleDate
12/30/2013
12/31/2013
1/1/2014

【问题讨论】:

    标签: python datetime pandas


    【解决方案1】:

    您没有正确解析日期。您应该传递列名而不是 True

    In [9]: df = pd.read_csv('mycsv.csv', parse_dates=['simpleDate'])
    
    In [10]: df.max()
    Out[10]: 
    simpleDate   2014-01-01 00:00:00
    dtype: datetime64[ns]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多