(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]

你可能感兴趣的:(Error,Record,#,小白学Python,ValueError,non-finite,Na,inf,astype)