Skip to content

spaces converted to todays date with to_datetime and read_csv date parse #6428

Closed
@hayd

Description

@hayd
In [265]: s = pd.Series(['10/18/2006', '10/18/2008', ' '])

In [266]: pd.to_datetime(s)
Out[266]:
0   2006-10-18
1   2008-10-18
2   2014-02-20
dtype: datetime64[ns]

In [268]: pd.to_datetime(s, errors='raise')
Out[268]:
0   2006-10-18
1   2008-10-18
2   2014-02-20
dtype: datetime64[ns]

Note: Can use pd.to_datetime(s, format='%m/%d/%Y', coerce=True).

This also seems to be the case when reading from csv.

csv = """case,opdate
7,10/18/2006
7,10/18/2008
621, """

In [282]: pd.read_csv(StringIO(csv), parse_dates=['opdate'])
Out[282]:
   case     opdate
0     7 2006-10-18
1     7 2008-10-18
2   621 2014-02-20

[3 rows x 2 columns]

See this SO question http://stackoverflow.com/questions/21922978/safest-pandas-read-csv-with-missing-dates/21924845#21924845

Maybe stems from:

In [284]: pd.datetools.parse(' ')
Out[284]: datetime.datetime(2014, 2, 20, 0, 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypeIO CSVread_csv, to_csvMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions