def filter_nans(x, y):
filtered = filter(lambda o: not math.isnan(o[0]) and not math.isnan(o[1]), zip(x, y))
return [el[0] for el in filtered], [el[1] for el in filtered]
例如:
x = [1, 2, 3, 4, 5, 6, None, 8]
y = [10, 'not a number', 30, 40, 50, 60, 70, 80]
x, y = filter_nans(x, y)
>>> x
[1, 3, 4, 5, 6, 8]
>>> y
[10, 30, 40, 50, 60, 80]
使用Python内置函数^{} 和^{} 尝试以下操作:
例如:
相关问题 更多 >
编程相关推荐