Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jreback opened this issue Apr 23, 2013 · 1 comment
Closed
Assignees
Labels
Refactor Internal refactoring of code
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Apr 23, 2013

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
@jreback
Copy link
Contributor Author

jreback commented May 8, 2013

closed by #3516

@jreback jreback closed this as completed May 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code
Projects
None yet
Development

No branches or pull requests

1 participant