'Converting to datetime - ParserError: Unknown string format: 2022-02-17 7

I have a pandas dataframe with some string values that have the hour of a date in one-digit format if the hour is smaller than 10, like this:

2022-02-17 7

I now want to get this strings to datetime format but when applying

df['datetime'] = pd.to_datetime(df['datetime'], infer_datetime_format=True)

I get a ParserError:

ParserError: Unknown string format: 2022-02-17 7

How can I solve this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source