Search code examples
pythonpandasdataframecsvencoding

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


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


Solution

  • 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")