3 Pandas functions I wish I'd known earlier

Pandas would have been the first library that you would have learnt or come across for data analysis or cleaning.

There are certain minimal operations that Pandas already has neat functions for.

Just makes your life much easier. Let’s take a quick look!

  1. idxmax and idxmin: This one’s quite straightforward. It just gives the index of the max or the min element in a Pandas Series or DataFrame.

And are you just like me wondering that what are argmax and argmin used for then?

Well, they are based on numpy arrays and using them on Pandas isn’t the right way as it will first convert it into numpy arrays and then operate.

  1. ne: This ones interesting.

There can be situations when a column contains 0s or any other value till a certain index, and you just want to skip them, or do some other operation wrt them.

Pandas ne returns True when the column value is not equal to the passed value.

It can be nicely chained with other functions like idxmax and then indexed efficiently.

  1. nlargest and nsmallest: These return the top n smallest or top n largest entries of a dataframe based on the column name passed.

And Pandas being as friendly as always, sorts them too for you! :slight_smile:

#machinelearning #datascience #python