I have a data frame in Pandas that has dates and some other data. The dates are explicitly of type datetime.date
. For the example, I'm forcing that by hand. In the real problem, the frame is imported from an external source already set that way. After manipulating the indexing, I find that my dates are of class pandas._libs.tslib.Timestamp
, which then causes incompatibilities with later code. What causes that change in type / class?
Minimal working example (note the differences between lines 3 and 7):
In [1]: df = pd.DataFrame({'date' : ['02/20/2015','01/15/2016','08/21/2015'], 'i' : ['Bob', 'Bob', 'Jim'] ,'v' : [1, 2, 3]})
In [2]: df['date'] = pd.to_datetime(df.date).dt.date
In [3]: print type(df.date[0])
<type 'datetime.date'>
In [4]: df.set_index(['i','date'], inplace=True)
In [5]: print type(df.loc['Bob',:].index[0])
<class 'pandas._libs.tslib.Timestamp'>
In [6]: df.reset_index(inplace=True)
In [7]: print type(df.date[0])
<class 'pandas._libs.tslib.Timestamp'>