Skip to content
Advertisement

Filter Nulls when converting pandas dataframe to dict

I have this pandas dataframe.

JavaScript

I am interested to convert every row into a dict.

JavaScript

So i use the above function and this trick

JavaScript

But the result i get is weird.

JavaScript

The last row had Language and Discount both as Nan.

And i expected that both should have been filtered out but i see only Language is filtered out.

How do i filter out all columns from the final result which are nan to filter out please ?

Advertisement

Answer

Use notna for filtering missing values:

JavaScript

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