【发布时间】:2019-11-11 17:07:49
【问题描述】:
我有一些 numpy.ndarray 变量。它们包括 nan 值,我想从中删除每个 nan 值。数组包含 int、float、str 等值。这些数组的一个例子:
['A' 'B' 'C' 'D' nan 'E' 'F']
另一个:
[nan 1.]
并且可能存在数组包含 float、str 和 nan 值的情况。在这种情况下,我怎样才能只删除 nan 值?
我使用了以下代码:
x[:, ~np.isnan(x).any(axis=0)]
并得到以下错误:
ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
【问题讨论】:
-
你试过 pandas
isnull吗?这可能有效
标签: python python-3.x nan numpy-ndarray