0

I've a datetime (int64) column in my pandas dataframe. I'm trying to convert its value of 201903250428 to a datetime value.

The value i have for the datetime (int64) column is only till minute level with 24 hours format.

I tried various methods like striptime, to_datetime methods but no luck.

pd.datetime.strptime('201903250428','%y%m%d%H%M')

I get this error when i use the above code.

ValueError: unconverted data remains: 0428

I wanted this value to be converted to like '25-03-2019 04:28:00'

1 Answer 1

1

Lower-case y means two-digit years only, so this is trying to parse "20" as the year, 1 as the month, 9 the day, and 03:25 as the time, leaving "0428" unconverted.

You need to use %Y which will work fine:

pd.datetime.strptime('201903250428','%Y%m%d%H%M')

http://strftime.org/ is a handy reference for time formatting/parsing parameters.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Daniel. Your answer helped me for this calculation. pd.to_datetime('201903250428',format='%Y%m%d%H%M',errors='coerce')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.