I am reading a sheet from excel file that contains block of hours. Excel sheet
cls.model_slots_result = pandas.read_excel(model_static_results_xlsx, sheet_name='model_slots',
engine='openpyxl')
When the time is 00:00:00, pandas load it as a Timestamp ('1899-12-30 00:00:00') i.e. Datetime in the dataframe even though other values (block of hours) of the same column are stored as datetime.time. Dataframe image
As of now I have created a function that checks if the type is datetime.time, if not it extracts time from datetime.
cls.model_slots_result['START_TIME'] = cls.model_slots_result['START_TIME'].apply(my_to_datetime)
cls.model_slots_result['END_TIME'] = cls.model_slots_result['END_TIME'].apply(my_to_datetime)
def my_to_datetime(datetime_obj):
if not isinstance(datetime_obj, time):
return datetime_obj.time()
return datetime_obj
Is there any way to make pandas return datetime.time object for 00:00:00 instead of a datetime object or make pandas read the the column as datetime.time?
Thanks