数据文件如下所示:
350 1.06k
351 1.10k
352 1.15k
所需输出:
350 1060
351 1100
352 1150
答案 0 :(得分:0)
这会有所帮助:
data = ['350 1.06k', '351 1.10k', '352 1.15k']
def convert(item):
item = item.split()
item[1] = str(float(item[1][:-1]) * 1000)[:-2]
return ' '.join(item)
res = [convert(i) for i in data]
print(res)
答案 1 :(得分:0)
import re
data = ['350 1.06k', '351 1.10k', '352 1.15k']
def covert_string(var):
return float(''.join(re.findall(r'\d+?.?', var)).replace(' ',''))*1000
for value in data:
print covert_string(value)
## -- End pasted text --
3501060.0
3511100.0
3521150.0
我希望这个解决方案适合你