Python | Панды Series.equals ()
Серия Pandas - это одномерный массив ndarray с метками осей. Этикетки не обязательно должны быть уникальными, но должны быть хешируемого типа. Объект поддерживает индексирование как на основе целых чисел, так и на основе меток и предоставляет множество методов для выполнения операций, связанных с индексом.
Pandas Series.equals() function test whether two objects contain the same elements. This function allows two Series or DataFrames to be compared against each other to see if they have the same shape and elements.
Syntax: Series.equals(other)
Parameter :
other : The other Series or DataFrame to be compared with the first.Returns : True if all elements are the same in both objects, False otherwise.
Example #1: Use Series.equals() function to check whether the underlying data in the two given series objects are same or not.
# importing pandas as pdimport pandas as pd # Creating the first Seriessr1 = pd.Series([80, 25, 3, 25, 24, 6]) # Creating the second Seriessr2 = pd.Series([80, 25, 3, 80, 24, 25]) # Create the Indexindex_ = ["Coca Cola", "Sprite", "Coke", "Fanta", "Dew", "ThumbsUp"] # set the first series indexsr1.index = index_ # set the second series indexsr2.index = index_ # Print the first seriesprint(sr1) # Print the second seriesprint(sr2) |
Выход :

Now we will use Series.equals() function to check if the underlying data in the two given series objects are same or not.
# check for equalityresult = sr1.equals(other = sr2) # Print the resultprint(result) |
Выход :

As we can see in the output, the Series.equals() function has returned False indicating the element in the two given series objects are not same.
Example #2: Use Series.equals() function to check whether the underlying data in the two given series objects are same or not.
# importing pandas as pdimport pandas as pd # Creating the first Seriessr1 = pd.Series([80, 25, 3, 25, 24, 6]) # Creating the second Seriessr2 = pd.Series([80, 25, 3, 25, 24, 6]) # Create the Indexindex_ = ["Coca Cola", "Sprite", "Coke", "Fanta", "Dew", "ThumbsUp"] # set the first series indexsr1.index = index_ # set the second series indexsr2.index = index_ # Print the first seriesprint(sr1) # Print the second seriesprint(sr2) |
Выход : 

Now we will use Series.equals() function to check if the underlying data in the two given series objects are same or not.
# check for equalityresult = sr1.equals(other = sr2) # Print the resultprint(result) |
Output :
As we can see in the output, the Series.equals() function has returned True indicating the element in the two given series objects are same.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.