解决TypeError: ufunc ‘isnan‘ not supported for the input types, and the inputs could not be safely coe
解决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’’
报错代码
print(np.isnan(data).any())
报错日志
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''
报错原因
数据列的类型不一致
print(data.info())
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 96453 entries, 0 to 96452
Data columns (total 12 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Formatted Date 96453 non-null datetime64[ns, UTC]
1 Summary 96453 non-null object
2 Precip Type 95936 non-null object
3 Temperature (C) 96128 non-null float64
4 Apparent Temperature (C) 96384 non-null float64
5 Humidity 96431 non-null float64
6 Wind Speed (km/h) 95156 non-null float64
7 Wind Bearing (degrees) 94189 non-null float64
8 Visibility (km) 96003 non-null float64
9 Loud Cover 0 non-null float64
10 Pressure (millibars) 95165 non-null float64
11 Daily Summary 96453 non-null object
dtypes: datetime64[ns, UTC](1), float64(8), object(3)
memory usage: 8.8+ MB
按数据类型单独处理,例如上述数据分为datetime64,float64,object
欢迎大家交流学习,任何问题都可以留言
还没有评论,来说两句吧...