Comparison Operations
Discover how to compare DataFrames with other objects using comparison methods.
We'll cover the following
Comparison operations
The pandas
library has a set of logical comparison operations for us to compare values in a DataFrame or Series
. While traditional operators like ==
, >
, and <
can be used to compare two sets of values, we can also use the wrapper methods like eq()
, gt()
, and lt()
for such comparisons.
The benefit of using these wrapper methods is that they offer greater flexibility, such as specifying the axis for comparison and indicating the MultiIndex level to work on. This benefit is similar to how arithmetic operation wrappers like add()
and div()
provide more flexibility and control compared to traditional operators like +
and /
.
The following table shows the matching wrapper method for each traditional comparison operator:
Get hands-on with 1200+ tech skills courses.