0

I'm trying to convert a pandas.core.series.Series object type to datetime using this:

pd.to_datetime(list(stops_data['arrival_time']),'%HH%MM%SS')

but python is throwing this:

---------------------------------------------------------------------------
Traceback (most recent call last)
<ipython-input-51-c92e51656d69> in <module>
----> 1 pd.to_datetime(list(stops_data['arrival_time']),'%HH%MM%SS')

/home/BLABLA/snap/jupyter/common/lib/python3.7/site-packages/pandas/core/tools/datetimes.py in to_datetime(arg, errors, dayfirst, yearfirst, utc, format, exact, unit, infer_datetime_format, origin, cache)
    739     elif is_list_like(arg):
    740         try:
--> 741             cache_array = _maybe_cache(arg, format, cache, convert_listlike)
    742         except tslibs.OutOfBoundsDatetime:
    743             # caching attempts to create a DatetimeIndex, which may raise

/home/BLABLA/snap/jupyter/common/lib/python3.7/site-packages/pandas/core/tools/datetimes.py in _maybe_cache(arg, format, cache, convert_listlike)
    150         unique_dates = unique(arg)
    151         if len(unique_dates) < len(arg):
--> 152             cache_dates = convert_listlike(unique_dates, format)
    153             cache_array = Series(cache_dates, index=unique_dates)
    154     return cache_array

/home/BLABLA/snap/jupyter/common/lib/python3.7/site-packages/pandas/core/tools/datetimes.py in _convert_listlike_datetimes(arg, format, name, tz, unit, errors, infer_datetime_format, dayfirst, yearfirst, exact)
    445             errors=errors,
    446             require_iso8601=require_iso8601,
--> 447             allow_object=True,
    448         )
    449 

/home/BLABLA/snap/jupyter/common/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py in objects_to_datetime64ns(data, dayfirst, yearfirst, utc, errors, require_iso8601, allow_object)
   1838     ValueError : if data cannot be converted to datetimes
   1839     """
-> 1840     assert errors in ["raise", "ignore", "coerce"]
   1841 
   1842     # if str-dtype, convert

AssertionError:

Context, in case my premise is wrong: I'm trying to find the ocurrence of a list of times (HH:MM:SS) in a schedule interval (HH:MM:SS), so I'm using numpy.digitize. For this, I have to create two numpy arrays but it gave me this error TypeError: Cannot cast array data from dtype('<U13') to dtype('float64') according to the rule 'safe' so I try to convert the data to de data type I actually need.

EDIT: I didn't solve this. I managed to do it converting all hours to integers and worked well, but still I would like to know what does this error means. Thanks!

AMC
  • 2,642
  • 7
  • 13
  • 35
Maltita
  • 69
  • 4
  • Please provide a [mcve]. _I'm trying to convert a `pandas.core.series.Series` object type to `datetime`_ What datetime type are you referring to? – AMC May 08 '20 at 16:01

1 Answers1

0

It should work as

pd.to_datetime(stops_data['arrival_time'])

Check this answer for more info.