Python Forum

Full Version: Mac - pathnames
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using Jupyter Notebooks on a Mac 10.13.4 High Sierra , Python 3.6.4.
I want matplotlib to plot (histogram) some data from a sample table (csv file) on my desktop. Its about cars.
Whatever I do I get a syntax error.I have tried changing the slash etc. I am following a Lynda.com tutorial. The tutorial (I am v new to Python) is written for Windows.
What is the accepted way to specify the path for Mac or even Multiplatform for portability - NB I am very inexperienced.

Many thanks
nick

address = /User/aaaaaaaaaa/Desktop/mtcars.csv
cars = pd.read_csv(address)
cars.columns = ['car_names', 'mpg', 'cyl', 'disp', 'hp', 'drat', 'wt', 'qsec', 'vs', 'am', 'gear','carb']
cars.index = cars.car_names
mpg = cars['mpg']

mpg.plot(kind='hist')
 
File "<ipython-input-18-ff5ef8e7c5db>", line 1
    address = /User/nicholasphillips/Desktop/mtcars.csv
              ^
SyntaxError: invalid syntax
you need to put in quotes
address = '/User/aaaaaaaaaa/Desktop/mtcars.csv'
Doh, - you are very kind and patient.