0

When executing the following Python 3.6 code in Jupyter 5.000 notebook:

import pandas as pd
file = "C:\users\frogf\MSDS7333\data\HIGGS.csv"
data=pd.read_csv(file,nrows=N,header=None,encoding = "utf-8")

it gives the error:

 File "<ipython-input-5-204f62a7e8b4>", line 2
    file = "C:\users\frogf\MSDS7333\data\HIGGS.csv"
          ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX escape
5
  • 1
    Probably because the file is not actually valid UTF-8 - what exactly is the content in that line? Commented Aug 14, 2018 at 10:22
  • 1
    You need to escape the back slashes or pass a raw string: file = r"C:\users\frogf\MSDS7333\data\HIGGS.csv" '\u' is a unicode escape sequence, if this is the error I'm voting to close as it's a typo Commented Aug 14, 2018 at 10:23
  • its a large dataset from Keras 2.6 GB download. Commented Aug 14, 2018 at 10:24
  • @EdChum looks exactly what is to me... positions 2 and 3 are \u and it's not a raw string... Commented Aug 14, 2018 at 10:27
  • adding escape chars worked. sorry to ask dumb question, please close it. Commented Aug 14, 2018 at 10:31

1 Answer 1

1

open the file as raw string. Try:

import pandas as pd
data=pd.read_csv(r"C:\users\frogf\MSDS7333\data\HIGGS.csv",nrows=10,header=None,encoding = "utf-8")
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.