I get a file not found error when I use a variable with raw string literal appended below, I believe because the file path contains \f which needs to be escaped, I want to have the path read as raw literal so have attempted to add the 'r' prefix to the path string manually and assign this to the variable I've called path as below, but it doesn't work.
import pandas as pd
path = raw_input("Enter location of data file:")
path = str('r"'+ str(path[1:]))
print path
try:
df=pd.read_excel(path)
except:
df= pd.read_csv(path)
df.head
prints r"C:\Users\faulknerdw\Anaconda\Progs\GW_data.csv"
but it works if I input what appears to be the exact same thing long-hand. e.g.
df=pd.read_excel(r"C:\Users\faulknerdw\Anaconda\Progs\GW_data.csv")
and
df= pd.read_csv(r"C:\Users\faulknerdw\Anaconda\Progs\GW_data.csv")
What's going on?