pd.to_numeric之后对象未转换为数字

时间:2018-07-16 13:04:48

标签: python pandas numeric

我不明白为什么我的列allHoldingsFund ['ratioBest']没有转换为数字?

最初,我用数字0代替了空行,但将int 0替换为浮点数并没有使列allHoldingsFund ['ratioBest']易于转换为数字(错误TypeError:未调整大小对象的len())。现在,我按原样保留了空行,并强制将浮点数转换为数字,但它不起作用-allHoldingsFund ['ratioBest']仍然是一个对象。见下文

allHoldingsFund['ratioBest']

Out[170]: 
100                          
144                          
187         0.520704845814978
264                          
386                          
494                          
597                          
635         2.790492957746479

allHoldingsFund['ratioBest']=pd.to_numeric(allHoldingsFund['ratioBest'], errors='coerce')

Name: ratioBest, Length: 1664, dtype: object

感谢您的帮助

谢谢

1 个答案:

答案 0 :(得分:1)

我遇到了您的问题-值不是标量,而是imResize.save(path + new_folder, 'JPEG', quality=90) s:

numpy.ndarray

解决方案先转换为allHoldingsFund = pd.DataFrame({'ratioBest':[np.array(4.12), '']}) print (allHoldingsFund) ratioBest 0 4.12 1 ,然后转换为list

1d array