Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'CSV does not exist' - Pandas DataFrame [duplicate]

Tags:

python

pandas

I'm having difficulty reading a csv file into the pandas data frame. I am a total newcomer to pandas, and this is preventing me from progressing. I have read the documentation and searched for solutions, but I am unable to proceed. I have tried the following to no avail...

import pandas as pd
import numpy as np
pd.read_csv('C:\Users\rcreedon\Desktop\TEST.csv')
pd.read_csv("C:\Users\rcreedon\Desktop\TEST.csv")

and similar permutations with/without quotation marks.

It spits out a large composite error that ends in:

IOError: File C:\Users
creedon\Desktop\TEST.csv does not exist

It seems strange that in the error it misses of the "r" from "rcreedon". Is this what's causing the problem?

Just for the sake of it i also tried

pd.read_csv('C:\rcreedon\Desktop\TEST.csv')

And again the 'r' was missed when the error was returned.

Sorry to be such a block head, but I'm struggling here....

Any help appreciated.

like image 956
Woody Pride Avatar asked Jul 15 '13 18:07

Woody Pride


2 Answers

"\r" usually is interpreted as a special character and means carriage return. Either add a 'r' prefix to your string literals which prevents this special sequence from being interpreted (e.g. path = r"foo\rar"), or, as already suggested, just use a normal slash as path delimiter. Python is intelligent enough for it to also work on Windows :-)

like image 199
Dr. Jan-Philip Gehrcke Avatar answered Sep 18 '22 21:09

Dr. Jan-Philip Gehrcke


Just use a raw string:

pd.read_csv(r'C:\Users\rcreedon\Desktop\TEST.csv')
like image 27
BrenBarn Avatar answered Sep 18 '22 21:09

BrenBarn