UnicodeDecodeError when reading CSV file in Pandas with Python

后端 未结 21 2285
野趣味
野趣味 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:52

    Simplest of all Solutions:

    import pandas as pd
    df = pd.read_csv('file_name.csv', engine='python')
    

    Alternate Solution:

    • Open the csv file in Sublime text editor or VS Code.
    • Save the file in utf-8 format.

    In sublime, Click File -> Save with encoding -> UTF-8

    Then, you can read your file as usual:

    import pandas as pd
    data = pd.read_csv('file_name.csv', encoding='utf-8')
    

    and the other different encoding types are:

    encoding = "cp1252"
    encoding = "ISO-8859-1"
    

提交回复
热议问题