确保两个Pandas DatetimeIndexes相同?

Dal*_*las 4 python pandas

我在比较两个DatetimeIndex不同长度的问题时遇到了一个问题assert,如下所示:

In [1]: idx1 = pd.date_range('2010-01-01','2010-12-31',freq='D')

In [2]: idx2 = pd.date_range('2010-01-01','2010-11-01',freq='D')

In [3]: assert (idx1 == idx2).all()
Run Code Online (Sandbox Code Playgroud)

我收到错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-ad2cfd6d11c2> in <module>()
----> 1 assert (idx1 == idx2).all()

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.10.1.dev_dcd9df7-py2.7-macosx-10.8-x86_64.egg/pandas/tseries/index.pyc in wrapper(self, other)
     75         result = func(other)
     76 
---> 77         return result.view(np.ndarray)
     78 
     79     return wrapper

AttributeError: 'NotImplementedType' object has no attribute 'view'
Run Code Online (Sandbox Code Playgroud)

如果没有实现,这是好的,但有没有一些熊猫这样做的方法?

注意: 我已成功使用以下内容:

In [3]: assert list(idx1) == list(idx2)
Run Code Online (Sandbox Code Playgroud)

所以,以下也有效:

In [3]: assert list(df.index) == list(testindex)
Run Code Online (Sandbox Code Playgroud)

但我想知道是否有更多的pandas方法可以做到这一点.

unu*_*tbu 5

In [1]: import pandas as pd

In [2]: idx1 = pd.date_range('2010-01-01','2010-12-31',freq='D')

In [3]: idx2 = pd.date_range('2010-01-01','2010-11-01',freq='D')

In [4]: idx3 = pd.date_range('2010-01-01','2010-12-31',freq='D')

In [5]: help(idx1.equals)
Help on method equals in module pandas.tseries.index:

equals(self, other) method of pandas.tseries.index.DatetimeIndex instance
    Determines if two Index objects contain the same elements.


In [6]: print(idx1.equals(idx2))
False

In [7]: print(idx1.equals(idx3))
True
Run Code Online (Sandbox Code Playgroud)