This is my first time working on a python project outside of school, so bear with me.

When I run the code below, I get the error

"(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated\uXXXXXXXX escape"

and the IDLE editor highlights the '(' before the argument of pd.read_csv.

I googled the error but got a lot of stuff that went way over my head.

The csv file in question is an excel file i saved as csv. should i save it some other way?

import pandas as pd
field = pd.read_csv("C:\Users\Glen\Documents\Feild.csv")

I just want to convert my excel data into a data frame and I don't understand why it was so easy in class, and it's now so difficult on my home pc.

1 Answers

0
Abdur Rehman On

The problem is with the path. There are two ways to mention the path while reading a csv file,

1- Use double backslashes,

pd.read_csv("C:\\Users\\Glen\\Documents\\Feild.csv")

2- Use single forwardslash,

 pd.read_csv("C:/Users/Glen/Documents/Feild.csv")

If these do not work, try this one,

pd.read_csv("C:\\Users\\Glen\\Documents\\Feild.csv", encoding='utf-8')

OR

pd.read_csv("C:/Users/Glen/Documents/Feild.csv", encoding='utf-8')