Reputation: 128
I have a dataframe full of lists (in many columns) and these have nans in them.
I need to eliminate the nans from each column leaving a correct list.
Example of a cell:
['tag_001', 'tag_07', nan, nan, nan]
How can I remove these nans in a pythonic way?
Thank you!
Upvotes: 2
Views: 215
Reputation: 535
the math
lib has a function which checks for nan. Easily use the filter function to return a new list that does not have a nan inside of it.
import math
filter(lambda n: not math.isnan(n), ['tag_001', 'tag_07', nan, nan, nan])
Upvotes: 1