I have a .csv file with two columns (Date and Time). The time zone is "Europe/Paris" with a +02:00 hours shift. The file is structured in 2 parts with two datetime formats.
| Date | Time |
|---|---|
| 08-11-25 | 11:00 |
| 08-11-25 | 11:09 |
| 08-11-25 | 11:20 |
| 08-11-25 | 11:30 |
| 08-11-25 | 11:40 |
| 08-11-25 | 11:50 |
| ... | ... |
| ... | ... |
| 9-22-25 | 11:00:00 PM |
| 09-22-25 | 11:10:00 PM |
| 09-22-25 | 11:20:00 PM |
| 09-22-25 | 11:30:00 PM |
| 09-22-25 | 11:40:00 PM |
| 09-22-25 | 11:49:59 PM |
| 09-23-25 | 0:00:00 AM |
| 09-23-25 | 0:10:00 AM |
| 09-23-25 | 0:20:00 AM |
| 09-23-25 | 0:30:00 AM |
| 09-23-25 | 0:40:00 AM |
| 09-23-25 | 0:50:00 AM |
| 09-23-25 | 1:00:00 AM |
| 09-23-25 | 1:10:00 AM |
I read the .csv file and set the date/hour with the following python script:
import pandas as pd
df = pd.read_csv('./Data.csv')
df['Date2'] = df['Date'] + ' ' + df['Time']
s = pd.to_datetime(df['Date2'],errors='coerce', format='%m-%d-%y %H:%M')
s = s.fillna(pd.to_datetime(df['Date2'], dayfirst=False, format='%m-%d-%y %I:%M:%S %p',errors='coerce' ))
df['Date2'] = s
There is no problem with the first format, but the second one is more tricky. As you can see below, I have a (timezone?) problem from midnight to 1 AM.
2025-09-23 23:00:00
2025-09-23 23:10:00
2025-09-23 23:20:00
2025-09-23 23:30:00
2025-09-23 23:40:00
2025-09-23 23:49:59
NaT
NaT
NaT
NaT
NaT
NaT
2025-09-24 01:00:00
2025-09-24 01:10:00
2025-09-24 01:20:00
2025-09-24 01:30:00
2025-09-24 01:39:59
2025-09-24 01:50:00
How can I solve this problem?