Python | Индекс панд. Идентичный ()

Опубликовано: 28 Марта, 2022

Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.

Pandas Index.identical() function determine if two Index objects contains the same elements. If they contain the same elements then the function returns True else the function returns False indicating the values contained in both the Indexes are different. This is similar to the Index.equals(), but check that other comparable attributes are also equal.

Syntax: Index.identical(other)

Parameters :
Other : index

Returns : boolean value

Example #1: Use Index.identical() function to check if two Indexes contain same elements and if other attributes are identical or not.

# importing pandas as pd
import pandas as pd
  
# Creating the first Index
idx1 = pd.Index(["Labrador", "Beagle", "Labrador", "Lhasa", "Husky", "Beagle"])
  
# Creating the second Index
idx2 = pd.Index(["Labrador", "Beagle", "Pug", "Lhasa", "Husky", "Pitbull"])
  
# Print the first and second Index
print(idx1, " ", idx2)

Выход :

Let’s check if the two Indexes are identical or not.

# Checking the equality of the two Indexes
idx1.identical(idx2)

Output :

As we can see in the output, the Index.identical() function has returned False indicating that the Indexes are not equal.
 
Example #2: Use Index.identical() function to check if the input indexes are identical to each other or not.

# importing pandas as pd
import pandas as pd
  
# Creating the first Index
idx1 = pd.Index(["Jan", "Feb", "Mar", "Apr", "May", "Jun",
                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"])
  
# Creating the second Index
idx2 = pd.Index(["Jan", "Feb", "Mar", "Apr", "May", "Jun",
                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"])
  
# Print the first and second Index
print(idx1, " ", idx2)

Выход :

Let’s check if the two Indices are identical to each other or not.

# test the equality
idx1.identical(idx2)

Выход :

The function has returned True indicating that both the Indexes are identical to each other.

Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.

Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.