I read a dataset that contains hours (i.e. 9:30 am) from a csv file. After exploring dataset, I saved it as a .xlsx
format. Now, I want to add some fields to this dataset, however, hours data are in float numbers between 0 to 1.
In other example, I converted those numbers to string
and it returned the hour. But with this format, this method just return float number in string format.
Consider this dataframe with an example of this data:
hours = [0.375, 0.41666666, 0.79166666, 0.79166666, 0.833333333, 0.375]
cities = ['AB', 'AC', 'AD', 'AF', 'AG', 'AT']
df = pd.DataFrame({'hour': hours, 'city': cities})
I have tried to convert to datetime the hours field
df['hours'] = [pd.to_datetime(i) for i in df['hour']]
However I got as a result:
1970-01-01 00:00:00
I was following this answer Converting a float to hh:mm format but time format is different from what I have in dataset.
Is there an specific method I can use in datetime
or in pandas
to convert those numbers to hours?