使用df.astype()强制类型转换,df['col']=df['col'].astype('float')

实际踩坑:
如果报错:TypeError: unsupported operand type(s) for +: 'int' and 'str'
解决:将第二个转成str,用astype(),如果转后,仍不能转,则大概率是数据的来源处,数据的格式不对!(读入的csv表,处理其中一列,提示这个报错,使用了series转dataframe,又series转array,执行仍然报以上的错误,强转提示:can't convert ......,最后确认是同事提供的csv,各种操作下,列下存的数据格式不对。)

相关文章:

  • 2021-10-02
  • 2021-11-05
  • 2022-12-23
猜你喜欢
  • 2022-01-05
  • 2022-12-23
  • 2019-11-22
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-11-12
相关资源
相似解决方案