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數組,解決方法就是將列數改為一致即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM