I had a pandas data frame in which one column contained dates given as strings (for exampel "2014-10-17"
. I wanted to have this values as Python date objects. I decided to make this transformation in two steps:
df.col = pandas.to_datetime(df.col)
df.col = df.map(lambda x : x.date())
Before the first step, after the first step and after the second step I used the same operation to check the content of the column:
df.col.tolist()[:5]
I have noticed that when the dates were given as strings
or datetime.date
the above operation operation was relative fast. In contrast, when the dates were given as pandas.datetime
objects, the operation was considerably slower.
Can someone explain this behavior?