df_cols
в проблемных случаях, вероятно, object
dtype.pandas
свободно использует этот тип d, как для строк или содержимого None
.
In [117]: np.nanmean(np.array([1.2,np.nan])) # a float array
Out[117]: 1.2
In [118]: np.nanmean(np.array([1.2,np.nan], object)) # object dtype array
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-118-ca706fd2a20e> in <module>
----> 1 np.nanmean(np.array([1.2,np.nan], object))
/usr/local/lib/python3.6/dist-packages/numpy/lib/nanfunctions.py in nanmean(a, axis, dtype, out, keepdims)
914 cnt = np.sum(~mask, axis=axis, dtype=np.intp, keepdims=keepdims)
915 tot = np.sum(arr, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
--> 916 avg = _divide_by_count(tot, cnt, out=out)
917
918 isbad = (cnt == 0)
/usr/local/lib/python3.6/dist-packages/numpy/lib/nanfunctions.py in _divide_by_count(a, b, out)
188 else:
189 if out is None:
--> 190 return a.dtype.type(a / b)
191 else:
192 # This is questionable, but currently a numpy scalar can
AttributeError: 'float' object has no attribute 'dtype'