解决TypeError: ufunc ‘isnan‘ not supported for the input types, and the inputs could not be safely coe

比眉伴天荒 2023-01-11 09:07 262阅读 0赞

解决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’’

报错代码

  1. print(np.isnan(data).any())

报错日志

  1. 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''

报错原因

数据列的类型不一致

  1. print(data.info())
  2. <class 'pandas.core.frame.DataFrame'>
  3. RangeIndex: 96453 entries, 0 to 96452
  4. Data columns (total 12 columns):
  5. # Column Non-Null Count Dtype
  6. --- ------ -------------- -----
  7. 0 Formatted Date 96453 non-null datetime64[ns, UTC]
  8. 1 Summary 96453 non-null object
  9. 2 Precip Type 95936 non-null object
  10. 3 Temperature (C) 96128 non-null float64
  11. 4 Apparent Temperature (C) 96384 non-null float64
  12. 5 Humidity 96431 non-null float64
  13. 6 Wind Speed (km/h) 95156 non-null float64
  14. 7 Wind Bearing (degrees) 94189 non-null float64
  15. 8 Visibility (km) 96003 non-null float64
  16. 9 Loud Cover 0 non-null float64
  17. 10 Pressure (millibars) 95165 non-null float64
  18. 11 Daily Summary 96453 non-null object
  19. dtypes: datetime64[ns, UTC](1), float64(8), object(3)
  20. memory usage: 8.8+ MB

按数据类型单独处理,例如上述数据分为datetime64,float64,object

欢迎大家交流学习,任何问题都可以留言

发表评论

表情:
评论列表 (有 0 条评论,262人围观)

还没有评论,来说两句吧...

相关阅读