zoukankan      html  css  js  c++  java
  • pandas-11 TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely错误解决方法

    pandas-11 TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely错误解决方法

    将一个list矩阵转化为numpy数组之后,使用np.isnan()方法,报出了这么一个错误:

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

    经过测试,发现是二维list转化为numpy数组的时候就存在问题了。
    出错原因是list第二维的元素个数不一致导致如:
    list1 = [[1, 2, 3],
    [4, 5, 6],
    [7, 8, 9, 10]]
    这时候使用 np.array(list1),输出如下内容:
    [
    list(1, 2, 3),
    list(4, 5, 6),
    list(7, 8, 9, 10)
    ]
    接着使用np.isnan()方法,就会报出最上面的错误。
    因为第三行是4个元素,所以无法转化为我们想要的numpy数组,解决方法就是将列数改为一致即可。

  • 相关阅读:
    C++分数类
    2019 SDN大作业
    个人作业-软工实践总结
    2019 SDN上机第7次作业
    2019 SDN上机第6次作业
    2019 SDN课程阅读作业(2)
    个人作业--软件评测
    2019 SDN上机第5次作业
    2019 SDN上机第4次作业
    2019 SDN第一次阅读作业
  • 原文地址:https://www.cnblogs.com/wenqiangit/p/11252776.html
Copyright © 2011-2022 走看看