0

New to pandas, running into an error consistently with WinXP file path, for example:

names1880 = pd.read_csv('C:\Documents and Settings\Foo\My Documents\pydata-book\pydata-book-master\ch02\names\yob1880.txt', names=['name', 'sex', 'births'])

Keep getting an error as follows:

Exception                                 Traceback (most recent call last)
 in ()
----> 1 names1880 = pd.read_csv('C:\Documents and Settings\Foo\My Documents\pydata-book\pydata-book-master\ch02\names\yob1880.txt', names=['name', 'sex', 'births'])

From reading thru available documentation, haven't isolated if its a problem with my syntax or a parser issue.

Any feedback would be appreciated.

2
  • 4
    You need to include the entire traceback, not just the first line. Commented Feb 26, 2013 at 22:15
  • Also use raw-strings or forward-slashes or escape your backslashes in your file path. Commented Feb 26, 2013 at 22:18

1 Answer 1

2

Unless you put r in front of the string, the \n is being interpreted as a newline:

In [1]: 'C:\Documents and Settings\Foo\My Documents\pydata-book\pydata-book-master\ch02\names\yob1880.txt'
Out[1]: 'C:\\Documents and Settings\\Foo\\My Documents\\pydata-book\\pydata-book-master\\ch02\names\\yob1880.txt'

vs

In [2]: r'C:\Documents and Settings\Foo\My Documents\pydata-book\pydata-book-master\ch02\names\yob1880.txt'
Out[2]: 'C:\\Documents and Settings\\Foo\\My Documents\\pydata-book\\pydata-book-master\\ch02\\names\\yob1880.txt'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.