3

I have a very simple error in Python with Spyder:

import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt 

ds=pd.read_csv(".\verikumesi\NBA_player_of_the_week.csv")

When I run the above code, the I get an error:

File "C:/Users/Acer/Desktop/MASAÜSTÜ/github/deneme.py", line 12 ds=pd.read_csv(".\verikumesi\NBA_player_of_the_week.csv") ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 12-13: malformed \N character escape

How can I fix it?

2

1 Answer 1

5
".\verikumesi\NBA_player_of_the_week.csv"

is invalid Python. In normal (non-raw) strings, the backslash combines with the following character to form an "character escape sequence", which mean something quite different. For example, "\n" means a newline character. There is no escape sequence "\N", and you don't want an escape sequence anyway, you want a backslash and a "N". One solution is to use raw strings (r"..."), which strip the backslash of its superpower. The other is to use a character escape sequence whose meaning is the backslash (\\).

tl;dr: Use either of these options:

r".\verikumesi\NBA_player_of_the_week.csv"
".\\verikumesi\\NBA_player_of_the_week.csv"
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your answer, now it's working
@AliÜSTÜNEL then, please, accept this answer. Thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.