You could get rid of columns withNone
in them like this (in either Python 2.7 or 3+):
from __future__ import print_function
try:
from itertools import izip
except ImportError:
izip = zip
ra = [0, 1, 2, float('nan'), 8 , 3, 8, 5]
ma = [3, float('nan'), 5, 8, 9, 6, 4, 10]
op = [7, None, 7, 9, 3, 6, None, 7]
ra, ma, op = izip(*(col for col in izip(ra, ma, op) if None not in col))
print('ra =', ra)
print('ma =', ma)
print('op =', op)
Output:
ra = (0, 2, nan, 8, 3, 5)
ma = (3, 5, 8, 9, 6, 10)
op = (7, 7, 9, 3, 6, 7)
As @Bakuriu mentioned in a comment, it might be a better to use thecompress()
function which is in the built-initertools
module and is therefore likely to be faster. It also eliminates the relatively slow linear search through each column of values in the above.
from itertools import compress
ra, ma, op = izip(*compress(izip(ra, ma, op), (x is not None for x in op)))