これは私がテストしたばかりのものです.pprintは必要ないかもしれません.明確な出力のために使用したいだけです.
test.csv
1000001234,Account Name,0,0,"3,711.32",0,0,"18,629.64","22,340.96",COD,"20,000.00",Some string,Some string 2
1000001234,Account Name,0,0,"3,711.32",0,0,"18,629.64","22,340.96",COD,"20,000.00",Some string,Some string 2
コードを作成し、csv リーダーを使用し、各項目を parseNum 関数に渡して有効な数字かどうかを確認します。
from pprint import pprint
import csv
def parseNum(x):
xx=x.replace(",","")
if not xx.replace(".","").isdigit(): return x
return "." in xx and float(xx) or int(xx)
x=[map(parseNum,line) for line in csv.reader(open("test.csv"))]
pprint(x)
出力
[[1000001234,
'Account Name',
0,
0,
3711.3200000000002,
0,
0,
18629.639999999999,
22340.959999999999,
'COD',
20000.0,
'Some string',
'Some string 2'],
[1000001234,
'Account Name',
0,
0,
3711.3200000000002,
0,
0,
18629.639999999999,
22340.959999999999,
'COD',
20000.0,
'Some string',
'Some string 2']]
注: 浮動小数点数に十分な精度が必要な場合は、floatをDecimalに置き換えます。