2
我不知道這一點,也許我越來越瞎找長期在同一個東西...CSV導入與Python的QUOTE_NONNUMERIC工作不正常
我有這種線在CSV文件:
""BIN"",""Afg"",""SONIC/SONIC JET/"",1,8.9095,""Due to the dynamic nature of the exemptions granted to many operators, the Contract Price does not reflect V.A.T./G.S.T., Mineral Oil Taxes, Federal Excise Taxes or other taxes to which an operator may be exempt. Please contact your salesperson or World Fuel Services if you require assistance in generating a fuel price estimate."",""N/A"",""01-NOV-2013"
我敢嘗試導入這樣的:
data = csv.DictReader(open(newdatafile), delimiter=',', quoting=csv.QUOTE_NONNUMERIC)
data.fieldnames = [
'iata', 'country', 'fbo', 'quantity', 'price', 'remarks', 'special', 'validdate'
]
for row in data:
fuelentry = FuelPriceImport()
fuelentry.iata = row['iata']
fuelentry.fbo = row['fbo']
fuelentry.min_quantity = row['quantity']
fuelentry.net_price_liter = row['price']
fuelentry.remarks = row['remarks']
fuelentry.save()
當我運行這段代碼,它總是抱怨:
could not convert string to float: the Contract Price does not reflect V.A.T./G.S.T.
這顯然是直接在雙引號字符串之後的逗號之後。
不應該QUOTE_NONNUMERIC
避免這一點,因爲整個文本是在雙引號內?
你的報價是* *一倍,這意味着該列被看作是加引號(報價翻了一番被引用引號)。 –
所以我應該嘗試從csv中刪除雙引號......從來沒有想過這可能是問題 – normic
我正在測試解決方法。 –