Easily compare data using Pandas

Gustavo Santos
gustavorsantos
Published in
5 min readAug 5, 2021

--

Compare columns to one or many thresholds using these methods…

Photo by Jason Dent on Unsplash

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.

--

--

Gustavo Santos
gustavorsantos

Data Scientist. I extract insights from data to help people and companies to make better and data driven decisions. | In: https://www.linkedin.com/in/gurezende/