Reindexing pandas timeseries from object dtype to datetime dtype

You could use pd.to_datetime:

In [1]: import pandas as pd

In [2]: pd.to_datetime('2008-02-27')
Out[2]: datetime.datetime(2008, 2, 27, 0, 0)

This allows you to “clean” the index (or similarly a column) by applying it to the Series:

df.index = pd.to_datetime(df.index)

or

df['date_col'] = df['date_col'].apply(pd.to_datetime)

Leave a Comment

File not found.