a newbie here. Could someone tell me why do we use an 'r' in some cases before the path name in the following function?:
df = pd.read_csv(r"Path_name")
Thanks in advance
a newbie here. Could someone tell me why do we use an 'r' in some cases before the path name in the following function?:
df = pd.read_csv(r"Path_name")
Thanks in advance
In Python, backslash is used to signify special characters.
For example, "hello\nworld" -- the \n means a newline. Try printing it.
Path names on Windows tend to have backslashes in them. But we want them to mean actual backslashes, not special characters.
r stands for "raw" and will cause backslashes in the string to be interpreted as actual backslashes rather than special characters.
e.g. r"hello\nworld" literally means the characters "hello\nworld". Again, try printing it.
More info is in the Python docs, it's a good idea to search them for questions like these.
https://docs.python.org/3/tutorial/introduction.html#strings
更多推荐
所有评论(0)