无法将数据转换为从字符串浮动

时间:2019-02-16 10:24:03

标签: python-3.x string pandas dataframe

给出一个数据帧中的列:df [“ BILL_AMT”],它具有字符串类型的值,我想将它们转换为float然后求和。

for b in df["BILL_AMT"]:
    print(b)

output:
 2,879,403.00
-2,938,167.00
1,990,609.00
-2,006.00

s=0
for b in df["BILL_AMT"]:
    s=s+float(b.strip(','))


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-51-742469fb1c93> in <module>
      1 s=0
      2 for b in df["BILL_AMT"]:
----> 3     s=s+float(b.strip(','))

ValueError: could not convert string to float: '2,879,403.00'




0 个答案:

没有答案