Skip to content
Advertisement

python pandas: filter out records with null or empty string for a given field

I am trying to filter out records whose field_A is null or empty string in the data frame like below:

JavaScript

This gives me error:

JavaScript

or

JavaScript

This one gave no error but didn’t filter out any None values.

I also tried:

JavaScript

This one doesn’t give error but doesn’t filter out any None values either.

Could anyone please advise how to solve this problem? Thanks!

Advertisement

Answer

Can you create a new dataframe from the filtering?

Dataframe before:

JavaScript

Example:

JavaScript

dataframe after:

JavaScript

What it is doing is looking for “null” and excluding it. You could do the same thing with empty strings.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement