Closed
Description
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)