10

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

1 Answer 1

17

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")
Sign up to request clarification or add additional context in comments.

2 Comments

How can you tell that `byte 0xff in position 0 means... utf-16."? I'm getting a similar error and was hoping to know how you go about determining the encoding based on the byte value.
Hi, I updated my answer and linked a great material about BOMs and encodings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.