当前位置:网站首页>Valueerror: invalid literal for int() with base 10 conversion error related to data type

Valueerror: invalid literal for int() with base 10 conversion error related to data type

2022-04-23 20:47:00 NuerNuer

1.ValueError: invalid literal for int() with base 10 

a Is a string , for example ‘108.8’
Error reason : Direct pair a Conduct int(a) operation , Grammar does not allow
terms of settlement :int(float(a)) or round(float(a)), That is, first convert the string to floating-point data , Then round

2.TypeError: Cannot cast array data from dtype(‘float64‘) to dtype(‘<U32‘)....

Error reason :‘U32’ and ’S32’ All means numpy An array is an array of strings , Not an array of numbers , Therefore, it cannot be directly converted to floating-point array , Be careful ,numpy Array , As long as one item is a string , The types returned by the array are all string arrays .
terms of settlement : take numpy Convert to floating point array , Reference code :

mx = mx.astype(float)


 

版权声明
本文为[NuerNuer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210545523170.html