

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Comparing two Pandas series and printing the the difference
In this program, we will compare two Pandas series and will print the differences in the series. By difference, we mean that the index positions at which the elements did not match.
Algorithm
Step 1: Define two Pandas series, s1 and s2. Step 2: Compare the series using compare() function in the Pandas series. Step 3: Print their difference.
Example Code
import pandas as pd s1 = pd.Series([10,20,30,40,50,60]) s2 = pd.Series([10,30,30,40,55,60]) print("S1:\n", s1) print("\nS2:\n", s2) difference = s1.compare(s2) print("\nDifference between the series: \n",difference)
Output
S1: 0 10 1 20 2 30 3 40 4 50 5 60 dtype: int64 S2: 0 10 1 30 2 30 3 40 4 55 5 60 dtype: int64 Difference between the series: self other 1 20.0 30.0 4 50.0 55.0
Explanation
In the above output, there are two columns in the difference output. One is 'self' and beside it is 'other'. The self refers to s1 series whereas the 'other' refers to s2 series.
- Related Questions & Answers
- How to handle the null values while comparing the two series objects using series.eq() method?
- Python Pandas - Compute the symmetric difference of two Index objects and unsort the result
- Python Pandas – Find the Difference between two Dataframes
- How to find the dot product of two pandas series objects?
- Python program to compare two Pandas series
- Python Pandas - Compute the symmetric difference of two Index objects
- Python Pandas - Create a Series from TimeDeltaIndex and set the index of the resulting Series
- Python Pandas - Create a Series from TimeDeltaIndex and set the name of the resulting Series
- Comparing two strings in MySQL?
- Comparing two strings in C++
- Comparing two dates in PHP
- Comparing Timestamp in Python – Pandas
- What is the difference between NumPy and pandas?
- Combining two Series into a DataFrame in Pandas
- Write a Python code to concatenate two Pandas series into a single series without repeating the index
Advertisements