Home > Net >  ValueError: time data does not match the given format
ValueError: time data does not match the given format

Time:11-19

df_time = pd.DataFrame({'DOB': {0: '12FEB20210017', 1: '18AUG20210019'}})

df_time['DOB'] = pd.to_datetime(df_time.DOB,format='%d%b%Y%H:%M:%S')

ValueError: time data '12FEB20210017' does not match format '%d%b%Y:%H:%M:%S' (match)

I don't understand the problem with the format

CodePudding user response:

The format needed a slight change.

   import pandas as pd
   df_time = pd.DataFrame({'DOB': {0: '12FEB20210017', 1: '18AUG20210019'}})
   #df_time['DOB'] = df_time['DOB'].str.lower()
   df_time['DOB'] = pd.to_datetime(df_time.DOB,format='%d%b%Y%H%M')

CodePudding user response:

as mentioned in the comments ,errror message is clear and your data format should be like this :

import pandas as pd

df_time = pd.DataFrame({'DOB': {0: '12FEB20210017', 1: '18AUG20210019'}})
df_time['DOB'] = pd.to_datetime(df_time.DOB,format='%d%b%Y%H%M%S')

df_time

output:

>
                  DOB
0 2021-02-12 00:01:07
1 2021-08-18 00:01:09
  • Related