I need to get a timestamp out of multiple time-formats like:
df['date'] = [29.05.2023 01:00:00,
29.05.2023,
28.05.2023 23:00:00]
At 00:00:00 on every day the time is missing and only the date has been logged.
I need the timestamp to look like this:
df['date'] = [29.05.2023 01:00:00,
29.05.2023 00:00:00,
28.05.2023 23:00:00]
>Solution :
Use to_datetime with dayfirst=True parameter, for final ouput DD.MM.YYYY HH:MM:SS use Series.dt.strftime:
df = pd.DataFrame({'date':['29.05.2023 01:00:00',
'29.05.2023',
'28.05.2023 23:00:00',
'4.10.2023']})
df['date'] = pd.to_datetime(df['date'], dayfirst=True).dt.strftime('%d.%m.%Y %H:%M:%S')
print (df)
date
0 29.05.2023 01:00:00
1 29.05.2023 00:00:00
2 28.05.2023 23:00:00
3 04.10.2023 00:00:00