I'm quite new to Python and I'm encountering a problem.
I have a dataframe where one of the columns is the departure time of flights. These hours are given in the following format : 1100.0, 525.0, 1640.0, etc.
This is a pandas series which I want to transform into a datetime series such as : S = [11.00, 5.25, 16.40,...]
What I have tried already :
- Transforming my objects into string :
S = [str(x) for x in S]
- Using datetime.strptime :
S = [datetime.strptime(x,'%H%M.%S') for x in S]
But since they are not all the same format it doesn't work
- Using parser from dateutil :
S = [parser.parse(x) for x in S]
I got the error :
'Unknown string format'
- Using the panda datetime :
S= pd.to_datetime(S)
Doesn't give me the expected result
Thanks for your answers !
spliton the point and then check the string length? If it is 3, then dodatetime (0,0,0,int(srting_before_point[0]),int(string_before_point[-2:]),after_point_string)and something similar if the length is 4.datetime.strptime(x,'%H%M.%S')does not work ?s = [f'{x:07.2f}' for x in s]. That will makes = ['1100.00', '0525.00', '1640.00']fors = [1100.0, 525.0, 1640.0].