Pandas read csv file error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Question:

I would like to open csv data but keep getting the same error, what can I do to succesfully open csv files using Python?

#Reading in the files
import pandas as pd
data1 = pd.read_csv("data1.csv")

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid start byte

Asked By: Afke

||

Answers:

byte 0xff in position 0 means that your .csv is probably encoded in utf-16.

Try this :

data1 = pd.read_csv("data1.csv", encoding="utf-16")
Answered By: Timeless
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.