UnicodeDecodeError when reading CSV file in Pandas with Python

后端 未结 21 2266
野趣味
野趣味 2020-11-22 04:27

I\'m running a program which is processing 30,000 similar files. A random number of them are stopping and producing this error...

File "C:\\Importer\\src         


        
相关标签:
21条回答
  • 2020-11-22 04:54

    You can try with:

    df = pd.read_csv('./file_name.csv', encoding='gbk')

    0 讨论(0)
  • 2020-11-22 04:58

    Try specifying the engine='python'. It worked for me but I'm still trying to figure out why.

    df = pd.read_csv(input_file_path,...engine='python')
    
    0 讨论(0)
  • 2020-11-22 04:58

    Please try to add

    encoding='unicode_escape'
    

    This will help. Worked for me. Also, make sure you're using the correct delimiter and column names.

    You can start with loading just 1000 rows to load the file quickly.

    0 讨论(0)
  • 2020-11-22 05:02

    In my case this worked for python 2.7:

    data = read_csv(filename, encoding = "ISO-8859-1", dtype={'name_of_colum': unicode}, low_memory=False) 
    

    And for python 3, only:

    data = read_csv(filename, encoding = "ISO-8859-1", low_memory=False) 
    
    0 讨论(0)
  • 2020-11-22 05:02

    You can try this.

    import csv
    import pandas as pd
    df = pd.read_csv(filepath,encoding='unicode_escape')
    
    0 讨论(0)
  • 2020-11-22 05:02

    I am using Jupyter-notebook. And in my case, it was showing the file in the wrong format. The 'encoding' option was not working. So I save the csv in utf-8 format, and it works.

    0 讨论(0)
提交回复
热议问题