pandas - Removing nan from list - Python -


i trying remove 'nan' list, refusing go. have tried both np.nan , 'nan'.

this code:

ztt = [] in z:     if != 'nan':         ztt.append(i)  ztt 

or:

ztt = [] in z:     if != np.nan:         ztt.append(i)  ztt 

i still getting output:

[[46.0, 34.0, 32.0, 40.0, 34.0, 29.0, 38.0, 39.0, 45.0, 32.0, 28.0, 43.0],  [32.0, 30.0, 67.0, 66.0, 28.0, 19.0, 39.0, 32.0, 51.0, 28.0, 20.0, 36.0],  [29.0, 24.0, 37.0, 31.0, 32.0, 34.0, 28.0, 31.0, 28.0, 33.0, 28.0, 39.0],  [27.0, 29.0, 35.0, nan, nan, nan, nan, nan, nan, nan, nan, nan]] 

anyone know going wrong?

ztt = [] z_i in z:     row = []     z_ij in z_i:         if math.isnan(z_ij):             row.append(z_ij)         # if want replace with, example, 0:         # else:         #     row.append(0)     ztt.append(row) 

alternatively, nested list comprehensions:

ztt = [[z_ij z_ij in zi if math.isnan(z_ij)] z_i in z] 

btw, if using numpy, can do:

import numpy np  ztt =[value[~np.isnan(value)] value in z] 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -