pandas.Index.equals
- Index.equals(other)[source]
-
Определяет, равны ли два объекта Index.
Сравниваются:
Элементы внутри объекта Index.
Порядок элементов внутри объекта Index.
- Parameters:
-
- other:Any
-
Другой объект для сравнения.
- Returns:
-
- bool
-
True, если “other” является объектом Index и имеет те же элементы и порядок, что и вызываемый индекс; False в противном случае.
Примеры
>>> 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
Тип данных не сравнивается
>>> 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
© 2008–2022, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.2.2/reference/api/pandas.Index.equals.html