Converting object datatype to date time format FB Prophet model

40 Views Asked by At

I have to convert the ds column to datetime format to use it in the fb prophet model in the format YYYY-MM-DD HH:MM:SS.

Date      Time                  

\[9357 rows x 3 columns\] ds
0    2004-10-03  18;00;00  2004-10-03 18:00:00
1    2004-10-03  19;00;00  2004-10-03 19:00:00
2    2004-10-03  20;00;00  2004-10-03 20:00:00
3    2004-10-03  21;00;00  2004-10-03 21:00:00
4    2004-10-03  22;00;00  2004-10-03 22:00:00

It's type is

date_time.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 9357 entries, 0 to 9356
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype         
---  ------  --------------  -----         
 0   Date    9357 non-null   datetime64[ns]
 1   Time    9357 non-null   object        
 2   ds      9357 non-null   object        
dtypes: datetime64[ns](1), object(2)
memory usage: 219.4+ KB

I am trying to convert it the required date time format. Tried with the below but however it still does not convert it to the required format.

data['ds'] = pd.to_datetime(data['ds'])

It's showing me the error->

KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3801             try:
-> 3802                 return self._engine.get_loc(casted_key)
   3803             except KeyError as err:

4 frames
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'format'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3802                 return self._engine.get_loc(casted_key)
   3803             except KeyError as err:
-> 3804                 raise KeyError(key) from err
   3805             except TypeError:
   3806                 # If we have a listlike key, _check_indexing_error will raise

KeyError: 'format'

Someone please help me in converting the format of this ds column. Thanks

The output should have been like-

 ds
0    2004-10-03 18:00:00
1    2004-10-03 19:00:00
2    2004-10-03 20:00:00
3    2004-10-03 21:00:00
4    2004-10-03 22:00:00

0

There are 0 best solutions below