我有一个列出值的列表,我得到的值之一是“ nan”
countries= [nan, 'USA', 'UK', 'France']
我试图将其删除,但每次都会收到错误消息
cleanedList = [x for x in countries if (math.isnan(x) == True)]
TypeError: a float is required
当我尝试这个:
cleanedList = cities[np.logical_not(np.isnan(countries))]
cleanedList = cities[~np.isnan(countries)]
TypeError: 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''
"nan"
,而不是实际的NaN值。