Pandas convert date and time to float

In my case the .csv file had strings as date and time with the following format:

30/07/2017 21:01:17

I find this to be the simplest way to convert this column to float:

df['dateTime'] = df['dateTime'].str.replace('/', '')
df['dateTime'] = df['dateTime'].str.replace(':', '')
df['dateTime'] = df['dateTime'].str.replace(' ', '')
df['dateTime'] = df['dateTime'].astype(float)

So we are removing any signs and spaces between digits and then converting the format to float so the final result would look like this:


Now we can use it in any numpy arrays and machine learning models. Got any better ideas? Please let us know in the comments! 🙂