I am trying to import files from the same folder, but put the r'location' on separate lines.
import pandas as pd
extra=r'C:\Users\Desktop\Pandas\'
visits=pd.read_csv(extra+r'visits.csv')
I get the EOL while scanning string literal error.
I am trying to import files from the same folder, but put the r'location' on separate lines.
import pandas as pd
extra=r'C:\Users\Desktop\Pandas\'
visits=pd.read_csv(extra+r'visits.csv')
I get the EOL while scanning string literal error.
This run:
import pandas as pd
extra=r'C:\Users\Desktop\Pandas\\'
visits=pd.read_csv(extra+r'visits.csv')
the backslash \ as the escape character before '.
In general, in python it is strongly recommended to use / instead of escape character \
Despite using raw string syntax, the syntax \' still escapes the last quote and tricks Python into thinking your string never ends.
You can just concatenate that last slash:
import pandas as pd
extra=r'C:\Users\Desktop\Pandas' + "\\"
visits=pd.read_csv(extra+r'visits.csv')
\ is an escape character which makes it possible to use ' within a string instead of marking its end.
I'd generally recommend / as path separator in python - it prevents you from exactly this type of annoying side effects.
extra = 'C:/Users/Desktop/Pandas/'
visits = pd.read_csv(extra + 'visits.csv')