piR*_*red 15 python indexing datetime pandas
如果我用type一个DataFrame,我知道有一个日期时间指数,我得到:
In [17]: type(df.index)
Out[17]: pandas.tseries.index.DatetimeIndex
Run Code Online (Sandbox Code Playgroud)
但是当我测试它时,我得到:
In [18]: type(df.index) == 'pandas.tseries.index.DatetimeIndex'
Out[18]: False
Run Code Online (Sandbox Code Playgroud)
我知道我认为类型的类型是一个字符串,但我真的不知道还有什么可以尝试,搜索没有产生任何结果.
And*_*den 24
您可以使用DatetimeIndex类的isinstance:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18249 次 |
| 最近记录: |