Convert a column of int64 (YYYYMMDDHHMMSS) into datetime64 without delimiters

Viewed 3298

this is the data in my pandas dataframe. i want to convert the dateTime column into a datetime64 so i can check if duplicate fileName exist then find the file with the latest dateTime

as you can see the datetime format here is YYYYMMDDHHMMSS without delimiters

                      filePath        dateTime fileName
0  Line20170601142525_line1.dat  20170601142525    line1
1  Line20170601142525_line2.dat  20170601142525    line2
2  Line20170601142526_line2.dat  20170601142526    line2
3  Line20170601142526_line3.dat  20170601142526    line3

Process finished with exit code 0

This is my code

formattedFileDirectory['dateTime'] = pandas.to_datetime(formattedFileDirectory['dateTime'], format='%Y%M%d%H%m%S')

i get this error

TypeError: 'int' object is unsliceable

if i set the column as string i get this error

ValueError: unconverted data remains: 5
2 Answers
Related