(20200410已解决)ValueError: Cannot convert non-finite values (NA or inf) to integer

  • 问题描述

    使用df['col'].astype(int)出现如题错误。

    原因是col列有些记录是空,所以没法转成int

  • 解决方案

    df['col'].fillna(0)
    

    将此列空值填充为0或其他数字,然后再使用df['col'].astype(int)转换数据格式。

  • References

  1. Data type conversion error: ValueError: Cannot convert non-finite values (NA or inf) to integer [duplicate]
发布了871 篇原创文章 · 获赞 1322 · 访问量 97万+

猜你喜欢

转载自blog.csdn.net/The_Time_Runner/article/details/105446579