Home > Enterprise >  I can not load CSV file using Google Colab
I can not load CSV file using Google Colab

Time:08-22

car_sales = pd.read_csv("/content/sample_data/car-sales.csv")
car_sales

The error:

--------------------------------------------------------------------------- UnicodeDecodeError Traceback (most recent call last) in 1 # Import "../data/car-sales.csv" and turn it into a DataFrame ----> 2 car_sales = pd.read_csv("/content/sample_data/car-sales.csv") 3 car_sales

9 frames /usr/local/lib/python3.7/dist-packages/pandas/_libs/parsers.pyx in pandas._libs.parsers.raise_parser_error()

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 8: invalid continuation byte

The file is saved in my /content/sample_data and the path is correct. enter image description here

CodePudding user response:

Try including an encoding param in your call, such as latin1 or iso-8859-1

Like so: pd.read_csv("/content/sample_data/car-sales.csv",encoding='latin1')

Try various encodings until you find the right one

EDIT: You can also try encoding_errors='ignore'

CodePudding user response:

try using this

car_sales= pd.read_csv('car-sales.csv', encoding='utf-8')

or change the encoding format

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

if it still not work then the csv file might not saved in a proper encoding save it in UTF-8 encoding

If none of this works kindly share the csv file in order to carry a investigation on the file

  • Related