I'm trying to convert a string to a date and I understand how to use the to_datetime that comes with pandas but I'd like to be able to do this without inserting a time? I'm sure this is very simple but I'm a little new to this.
Asked
Active
Viewed 162 times
0
-
You don't need a time component. – Burhan Khalid Feb 23 '15 at 09:35
-
Actually `to_datetime` also does the same thing as my answer, so what specifically is your issue? – EdChum Feb 23 '15 at 09:35
1 Answers
1
You don't need the time component, if you use the datetime.strptime
or to_datetime
the conversion is the same:
In [10]:
df = pd.DataFrame({'date':['2012/04/06']})
df
Out[10]:
date
0 2012/04/06
In [11]:
import datetime as dt
df['date'].apply(lambda x: dt.datetime.strptime(x, '%Y/%m/%d'))
Out[11]:
0 2012-04-06
Name: date, dtype: datetime64[ns]
In [13]:
pd.to_datetime(df['date'])
Out[13]:
0 2012-04-06
Name: date, dtype: datetime64[ns]

EdChum
- 376,765
- 198
- 813
- 562