0

I can convert a Timestamp to datetime easily:

>>> time = pd.Timestamp('2016-02-05 00:02:00')
Timestamp('2016-02-05 00:02:00')
>>> time.to_datetime()
datetime.datetime(2016, 2, 5, 0, 2)

But for some reason when I try to apply this to an entire Series the values don't change types:

>>> time = pd.Series([pd.Timestamp('2016-02-05 00:02:00'), pd.Timestamp('2016-02-05 00:03:00'), pd.Timestamp('2016-02-05 00:04:00')])
0   2016-02-05 00:02:00
1   2016-02-05 00:03:00
2   2016-02-05 00:04:00
dtype: datetime64[ns]
>>> time.apply(lambda x: x.to_datetime())
0   2016-02-05 00:02:00
1   2016-02-05 00:03:00
2   2016-02-05 00:04:00
dtype: datetime64[ns]

How can I convert that entire series into datetime?

Len
  • 1
  • to_datetime() for Series returns a datetime64 Series. http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html If you want it as timestamps you can convert it to a list with `[_.to_datetime() for _ in time]`. It depends on what will you use it for. – Javier Aug 11 '16 at 15:02
  • You may no be able to do so: IIUC, pandas stores datetime-like entries in `Series` and `DataFrame` as `Timestamp` objects. From the `Timestamp` class docstring: *TimeStamp is the pandas equivalent of python's Datetime and is interchangable with it in most cases. It's the type used for the entries that make up a DatetimeIndex, and other timeseries oriented data structures in pandas* – Alicia Garcia-Raboso Aug 11 '16 at 15:11
  • possible duplicate of https://stackoverflow.com/questions/37644199/pandas-convert-timestamp-column-to-datetime – Eulenfuchswiesel Jun 29 '18 at 12:06

0 Answers0