我是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
尝试一下:
#!/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)