Pandas – Cleaning the Data

To clean the data in Python, we have some built-in functions. In this lesson, we will understand them one by one with examples. Cleaning the data in Pandas means working on the incorrect data to fix it. This incorrect data can empty data, null, duplicate data, etc.


Read: Handle Duplicate Data in Pandas


Let’s say we have the following CSV file demo.csv. The data consists of some null values:

Demo CSV file in Pandas

Let us now work around the functions to clean the data:

  • isnull(): Find the NULL values and replace them with True.
  • notnull(): Find the NOT NULL values and replace them with True.
  • df.dropna(): Drop rows with NULL values.
  • df.fillna(x): Replace NULL values with a specific value

Pandas isnull() method

The isnull() method in Pandas is used to find the NULL values and replace them with True. For non-NULL values, False is returned. Let us see an example:

Output

Pandas notnull() method

The notnull() method in Pandas is used to find the NOT NULL values and replace them with True. For NULL values, False is returned. Let us see an example:

Output

Pandas dropna() method

The dropna() method in Pandas is used to drop and remove rows with null values. Let us see an example:

Output

Pandas fillna() method

The fillna() method in Pandas is used to replace NULL values with a specific value. Let us see an example:

Output

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others:


For Videos, Join Our YouTube Channel: Join Now


Read More:

Indexing in Pandas
Pandas - Group the Data
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading