Easily compare data using Pandas
Compare columns to one or many thresholds using these methods…
I enjoy discovering new Pandas methods. Like I heard the other day, that library is a wonder box and it is easy enough to fall in love with it.
You think of something related to data manipulation or transformation, the library probably has a method for that.
Today I present you a couple of them that work similarly:
- Less Than:
df.lt(other, axis)
- Greater Than:
df.gt(other, axis)
- Less or Equal to:
df.le(other, axis)
- Greater or Equal to:
df.ge(other, axis)
Why to use them?
The reason why should one use the methods, in my humble opinion, is because the functions written by the Pandas team are usually vectorized, so they tend to be fast. Of course you can create your own rule or code, but why to reinvent the wheel when it’s already there, right?
Use Cases
Well, this certainly vary from project to project, but I use it when I have to compare some columns to a minimum or a threshold and count how many passed, for example.
I can also think of a program that assesses which student passed a list of exams, maybe.