Home > Net >  Can't change this to pandas datetime
Can't change this to pandas datetime

Time:11-06

dfff = pd.DataFrame({'date': ['01-01-2016 0.55', '01-01-2016 1.26', '01-01-2016 4.51', 
                    '01-01-2016 7.43']}) 
print(dfff)

s1 = dfff.apply(pd.to_datetime)

*Error* : **ParserError: Unknown string format: 01-01-2016 0.55

**

when I try to apply the DateTime the error is showing I even tried to do formating but no use

CodePudding user response:

pd.to_datetime expects year, month, day and hour minute second and millisecond for the maximum number of parameters. utc time is T24:01:01.123Z

01-01-2016 0.55 change to 01-01-2016 0:55:00 using a regular expression then try pd.to_datetime

CodePudding user response:

You explicitly specify the format you want:

s1 = pd.to_datetime(dfff.date, format='%d-%m-%Y %H.%M')

s1
0   2016-01-01 00:55:00
1   2016-01-01 01:26:00
2   2016-01-01 04:51:00
3   2016-01-01 07:43:00
  • Related