Using Python 3.6 and Pandas 0.19.2: How do you read in an excel file and change a column to datetime straight from read_excel
? Similar to This Question about converters and dtypes. But I want to read in a certain column as datetime
I want to change this:
import pandas as pd
import datetime
import numpy as np
file = 'PATH_HERE'
df1 = pd.read_excel(file)
df1['COLUMN'] = pd.to_datetime(df1['COLUMN']) # <--- Line to get rid of
into something like:
df1 = pd.read_excel(file, dtypes= {'COLUMN': datetime})
The code does not error, but in my example, COLUMN
is still a dtype of int64
after calling print(df1['COLUMN'].dtype)
I have tried using np.datetime64
instead of datetime
. I have also tried using converters=
instead of dtypes=
but to no avail. This may be nit picky, but would be a nice feature to implement in my code.