SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes

created at 07-03-2022 views: 20

problem

SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: malformed \N character escape

It roughly means that the encoder cannot decode the bytes at positions 2-3

The reason for this is generally that when we need the path of the folder as the parameter of the function, the path interval symbol under the windows system is '', and this is also the escape character in python, so there may be errors when identifying,

solution

Add r in front of the path to cancel the effect of the escape character

For example the following path

pd.read_csv("D:\master\train\train.csv")

add r

pd.read_csv(r"D:\master\train\train.csv")
created at:07-03-2022
edited at: 07-03-2022: