Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mac - pathnames
#1
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
Reply
#2
you need to put in quotes
address = '/User/aaaaaaaaaa/Desktop/mtcars.csv'
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Doh, - you are very kind and patient.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020