蓝胖子899 2023-12-17 19:59 采纳率: 0%
浏览 4

python中空值补0报错

空值补0一直报错,不知带什么情况,有没有哥帮忙解答一下谢谢。
代码如下

for i in train.columns:
    for j in train.index:
        if np.isnan(train[i][j]):
            train[i][j] = 0

报错
Traceback (most recent call last):
  File "C:\Users\zr041\Desktop\test\happiness.py", line 40, in <module>
    if np.isnan(train[i][j]):
       ^^^^^^^^^^^^^^^^^^^^^
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''

Process finished with exit code 1

数据类型如下:

   id  happiness  ...  public_service_8  public_service_9
0   1          4  ...                50                50
1   2          4  ...                60                60
2   3          4  ...                90                75
3   4          5  ...                80                80
4   5          4  ...                50                50

  • 写回答

1条回答 默认 最新

  • 柯本 2023-12-17 20:21
    关注

    np.isnan的参数只能是list或np.array,若你的train是pd或openpyxl中的类型的话,它应该是不能直接用的

    评论

报告相同问题?

问题事件

  • 创建了问题 12月17日

悬赏问题

  • ¥15 Matlab安装yalmip和cplex功能安装失败
  • ¥15 加装宝马安卓中控改变开机画面
  • ¥15 STK安装问题问问大家,这种情况应该怎么办
  • ¥15 更换了一个新的win10系统,再下载VS时碰到的问题,是C++组件的?
  • ¥15 关于罗技鼠标宏lua文件的问题
  • ¥15 halcon ocr mlp 识别问题
  • ¥15 已知曲线满足正余弦函数,根据其峰值,还原出整条曲线
  • ¥20 无法创建新的堆栈防护界面
  • ¥15 sessionStorage在vue中的用法
  • ¥15 wordpress更换域名后用户图片头像不显示