Identify and Remove Nulls With Pandas

Null values ​​can be a source of problems and annoying headaches when we are working with datasets. In this short article, we will see how to identify them and proceed with their removal.

Harish Maddukuri
Geek Culture

--

Photo by Vitaly Vlasov from Pexels

Where are null values?

Let’s imagine we have a data frame called df and don’t know if it contains null values. We can check immediately with the command df.isnull().

print ( df.isnull() )
  • If you're using the Jupyter Notebook, you can omit the print command, you can simply use
df. isnull()

we will see a version of our data-frame similar to the following:

Image by Author

As we can see, for some columns and rows, we find the indication True which indicates that the value normally located in that position of the data frame is a null value.

How many null values ​​are there?

The visualization obtained is not ideal if you want to have an overview. To do this, we can add the sum () function :

--

--