Skip to content
Advertisement

Modifying data frame containing NaN value so that I don’t get not a number error on division

I have a pandas data frame with some NaN values which I have replaced by

JavaScript

Now one of my functions does the following:

JavaScript

Since I have replaced the NaN value by “”, I am getting

JavaScript

What should be the apt way to fill the NaN values so that I can get rid of this particular error?

Advertisement

Answer

You could filter your df to have only rows where ‘TEXT’ is not null, not an empty string, etc., then iterate through that filtered df. See these toy examples for some of the ways to filter the df:

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