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.
CodePudding user response:
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.