It means you have an extra space. Though pd.to_datetime
is very good at parsing dates normally without any format specified, when you actually specify a format, it has to match EXACTLY.
You can likely solve your issue by adding .str.strip()
to remove the extra whitespace before converting.
import pandas as pd
df['Time stamp'] = pd.to_datetime(df['Time stamp'].str.strip(), format='%d/%m/%Y')
Alternatively, you can take advantage of its ability to parse various formats of dates by using the dayfirst=True
argument
df['Time stamp'] = pd.to_datetime(df['Time stamp'], dayfirst=True)
Example:
import pandas as pd
df = pd.DataFrame({'Time stamp': ['01/02/1988', '01/02/1988 ']})
pd.to_datetime(df['Time stamp'], format= '%d/%m/%Y')
ValueError: unconverted data remains:
pd.to_datetime(df['Time stamp'].str.strip(), format='%d/%m/%Y')
#0 1988-02-01
#1 1988-02-01
#Name: Time stamp, dtype: datetime64[ns]
pd.to_datetime(df['Time stamp'], dayfirst=True)
#0 1988-02-01
#1 1988-02-01
#Name: Time stamp, dtype: datetime64[ns]