从csv读取到pandas,chardet和error bad lines选项在我的cas中不起作用

2024-07-04 05:22:45 发布

您现在位置:Python中文网/ 问答频道 /正文

在我写这篇文章之前,我检查了类似的问题,也尝试使用try/except。。。在那里尝试什么都不做,除了打印错误的线条,但无法解决我的问题。所以目前我有:

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)

但我还是得到了一个错误:

^{pr2}$

在open csv中是否有类似error='replace'的选项?或任何其他解决方案


Tags: csvtheimportreaddataas错误error

热门问题