pandas.Index.equals#
- Index.equals(other)[源代码]#
确定两个 Index 对象是否相等。
正在比较的内容是:
Index 对象内的元素。
Index 对象内元素的顺序。
- Parameters:
- otherAny
要与之比较的另一个对象。
- Returns:
- bool
如果 “other” 是一个 Index 并且它与调用索引具有相同的元素和顺序,则返回 True;否则返回 False。
Examples
>>> idx1 = pd.Index([1, 2, 3]) >>> idx1 Index([1, 2, 3], dtype='int64') >>> idx1.equals(pd.Index([1, 2, 3])) True
元素被比较
>>> idx2 = pd.Index(["1", "2", "3"]) >>> idx2 Index(['1', '2', '3'], dtype='object')
>>> idx1.equals(idx2) False
顺序被比较
>>> ascending_idx = pd.Index([1, 2, 3]) >>> ascending_idx Index([1, 2, 3], dtype='int64') >>> descending_idx = pd.Index([3, 2, 1]) >>> descending_idx Index([3, 2, 1], dtype='int64') >>> ascending_idx.equals(descending_idx) False
dtype 不 被比较
>>> int64_idx = pd.Index([1, 2, 3], dtype='int64') >>> int64_idx Index([1, 2, 3], dtype='int64') >>> uint64_idx = pd.Index([1, 2, 3], dtype='uint64') >>> uint64_idx Index([1, 2, 3], dtype='uint64') >>> int64_idx.equals(uint64_idx) True