Skip to content

CLN: convert_objects(convert_dates='force') should use to_datetime() #3423

@jreback

Description

@jreback

http://stackoverflow.com/questions/16157939/pandas-read-csv-fills-empty-values-with-string-nan/16158762#16158762

The convert_objects(convert_dates='force') should really just to
to_datetime()....

In [1]: In [1]: data = """
   ...:    ...:    value      date id
   ...:    ...: 0      2  2013-3-1  a
   ...:    ...: 1      3  2013-3-1  b
   ...:    ...: 2      4  2013-3-1  c
   ...:    ...: 3      5       nan  d
   ...:    ...: 4      6  2013-3-1  d
   ...:    ...: """

In [2]: In [15]: df = pd.read_csv(StringIO(data[1:]),index_col=0,sep='\s+')

In [3]: df.dtypes
Out[3]: 
...:     float64
value    float64
date      object
id        object
dtype: object

In [4]: In [24]: pd.to_datetime(df['date'])
Out[4]: 
...:   2013-03-01 00:00:00
...:   2013-03-01 00:00:00
...:   2013-03-01 00:00:00
...:                   NaT
...:   2013-03-01 00:00:00
...:                   NaT
Name: date, dtype: datetime64[ns]

In [5]: df['date'].convert_objects(convert_dates=True)
Out[5]: 
...:    2013-3-1
...:    2013-3-1
...:    2013-3-1
...:         NaN
...:    2013-3-1
...:        None
Name: date, dtype: object

Metadata

Metadata

Assignees

Labels

RefactorInternal refactoring of code

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions