Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

<class 'datetime.time'> is not convertible to datetime

I want to convert datatype object to datetime but I have this error :

<class 'datetime.time'> is not convertible to datetime

Here is my code :

time_df = time_df.rename(columns={"TIME_START": "hour"})
time_df["hour"] = pd.to_datetime(time_df["hour"]).dt.time

data_h_df['hour'] = data_df['time_utc'].dt.time
data_h_df['hour'] = pd.to_datetime(data_h_df["hour"]).dt.time

I have two dataframes, my problem is hour variable I want to change datatype object to datetime.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Convert to strings:

data_h_df['hour'] = pd.to_datetime(data_h_df["hour"].astype(str)).dt.time

but why converted times to datetimes and then to times? In my opinion in data_h_df['hour'] are datetimes, expected ouput before your solution.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading