[英]<class ‘decimal.ConversionSyntax’> errors when importing data from a CSV file using Python (tried using CSV and Pandas)
I have a CSV file from a small business that represents their records for about 70,000 orders spread out over about 30 years.我有一个来自一家小型企业的 CSV 文件,该文件代表了他们在大约 30 年内分布的大约 70,000 个订单的记录。 My goal is to store this data in a Django project with a DecimalField in the model setup to receive the import.
我的目标是将这些数据存储在 Django 项目中,并在 model 设置中使用 DecimalField 来接收导入。
Before trying to store the data in Django I'm first trying to import this data into Python.在尝试将数据存储在 Django 之前,我首先尝试将此数据导入 Python。 While most of the records import fine there are about 1 in 1000 that throw off a <class 'decimal.ConversionSyntax'> error during the import.
虽然大多数记录导入正常,但在导入期间大约有 1000 条记录抛出 <class 'decimal.ConversionSyntax'> 错误。 This is causing me to get incorrect data into Python.
这导致我将不正确的数据输入 Python。 I need to either fix how it reads the data or fix the problem in the data itself.
我需要修复它读取数据的方式或修复数据本身的问题。
None of this has resolved the issue.这些都没有解决问题。
How can I figure out what is wrong with this data and resolve this error?我怎样才能找出这些数据有什么问题并解决这个错误?
You can use chardet
to detect the encoding.您可以使用
chardet
来检测编码。
import chardet
with open('csv_of_text.csv','rb') as fraw: # "rb" = bytes mode
file_content = fraw.read()
chardet.detect(file_content)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.