2017-04-16 23 views
0

在我写这里之前,我也检查过类似的问题,我也尝试过使用try/except ...在哪里尝试什么都不做,除了打印坏行但无法解决我的问题。所以目前我有:从csv读到熊猫,chardet和错误的坏行选项在我的情况下不起作用

import pandas as pd 
import chardet 

# Read the file 
with open("full_data.csv", 'rb') as f: 
    result = chardet.detect(f.read()) # or readline if the file is large 

df1 = pd.read_csv("full_data.csv", sep=';', 
        encoding=result['encoding'], error_bad_lines=False, low_memory=False, quoting=csv.QUOTE_NONE) 

但我仍然得到错误:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 9: invalid start byte 

是否有类似的任何选择错误=在打开CSV“取代”?或任何其他解决方案

+0

哦,首先你正在阅读的二进制模式的文件,以确定编码,但随后你喂养它的df,为纯文本。你可以发布你的csv的几行,或至少确定内容? – Michal

+0

我觉得有一些俄罗斯,拉丁和中国的字符,我不介意用'?'替换它们。或其他任何东西 – edyvedy13

+0

好的,但首先,为什么你使用二进制阅读模式来确定编码? – Michal

回答

0

使用引擎选项sovles我的问题:

df1 = pd.read_csv("full_data.csv", sep=";", engine="python") 
相关问题