If I use type
on a DataFrame
which I know has a datetime index, I get:
In [17]: type(df.index)
Out[17]: pandas.tseries.index.DatetimeIndex
but when I test it, I get:
In [18]: type(df.index) == 'pandas.tseries.index.DatetimeIndex'
Out[18]: False
I know I assumed the type of type is a string, but I really don't know what else to try, and searching has resulted in nothing.
You can use isinstance of the DatetimeIndex class:
In [11]: dates = pd.date_range('20130101', periods=6)
In [12]: dates
Out[12]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-01 00:00:00, ..., 2013-01-06 00:00:00]
Length: 6, Freq: D, Timezone: None
In [13]: isinstance(dates, pd.DatetimeIndex)
Out[13]: True
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments