Let's say I have a dictionary:
dict_1 = {
"key_1": [0., 5.6, 6.1, np.nan],
"key_2": ["a", "t", "g", "r"],
"key_3": [6.7, np.nan, 5.6, 4.1]
}
All keys have values that are list and they all have the same length. I want to filter out the elements that are np.nan
(including the elements in the other keys that have the same index), so this is the desired output:
result = {
"key_1": [0., 6.1],
"key_2": ["a", "g"],
"key_3": [6.7, 5.6]
}
Can someone please help? I don't want to do for loop
because that's slow. I tried np.isnan(task_dictionary.values()).any(axis=1)
but it failed because key_2
element type is string.
Thanks!