I want to keep only numbers from an numpy array of strings, which are not necessarily valid. My code looks looks like the following:
age = train['age'].to_numpy() # 200k values
set(age)
# {'1', '2', '3', '7-11', np.nan...} 
age  = np.array(['1', '2', '3', '7-11', np.nan])
Desired output:
np.array([1, 2, 3]).  Ideally, '7-11' would be 7, however, that's not simple and is a tolerable loss.
np.isfinite(x) gives "ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''"
x = [num for num in age if isinstance(num, (int, float))] returns []
 
     
    