Python-浮动警告,删除逗号

问题描述 投票:-1回答:1

我是Python新手,

我有这个价格:1,304.20-1,500.20-4.10-140.50如何删除逗号?

for open_price in df_open:
    if ',' in open_price:
        open_priceClean = open_price.replace(',', '')
        continue
    prices.append(float(open_priceClean))

我收到此警告:

TypeError
Traceback (most recent call last) <ipython-input-67-80afd251c13d> in <module>()
     10 #Create the dependent data set 'y' as prices
     11 for open_price in df_open:
---> 12     if ',' in open_price:
     13         open_priceClean = open_price.replace(',', '')
     14         continue

TypeError: argument of type 'float' is not iterable
python dataframe
1个回答
0
投票

尝试一下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
df_open = open("test.txt","r")
read_file = df_open.read().splitlines()
print (read_file)

for line in read_file:
    no_comas = (line.replace(",",""))
    print (no_comas)
© www.soinside.com 2019 - 2024. All rights reserved.