1

I'm following Lesson 1 (http://nbviewer.jupyter.org/urls/bitbucket.org/hrojas/learn-pandas/raw/master/lessons/01%20-%20Lesson.ipynb) on using Pandas with the Jupyter console from Anaconda.

I'm trying to export a DataFrame (dict) to a CSV file, here is my code, which matches the instruction in Lesson 1 :

df.to_csv('births1880.csv',index=False,header=False)

I'm pulling out my hair, bc I keep getting an error msg., and I don't know why. Here is the error message :

PermissionError                           Traceback (most recent call last)
<ipython-input-29-cb4a3386d140> in <module>()
----> 1 df.to_csv('births1880.csv',index=False,header=False)

/Applications/anaconda/lib/python3.5/site-packages/pandas/core/frame.py in to_csv(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, compression, quoting, quotechar, line_terminator, chunksize, tupleize_cols, date_format, doublequote, escapechar, decimal, **kwds)
   1342                                      doublequote=doublequote,
   1343                                      escapechar=escapechar, decimal=decimal)
-> 1344         formatter.save()
   1345 
   1346         if path_or_buf is None:

/Applications/anaconda/lib/python3.5/site-packages/pandas/formats/format.py in save(self)
   1524             f = _get_handle(self.path_or_buf, self.mode,
   1525                             encoding=self.encoding,
-> 1526                             compression=self.compression)
   1527             close = True
   1528 

/Applications/anaconda/lib/python3.5/site-packages/pandas/io/common.py in _get_handle(path, mode, encoding, compression)
    422                 f = open(path, mode, encoding=encoding)
    423             else:
--> 424                 f = open(path, mode, errors='replace')
    425         else:
    426             f = open(path, mode)

PermissionError: [Errno 13] Permission denied: 'births1880.csv'
dartdog
  • 10,432
  • 21
  • 72
  • 121
Louis Flores
  • 11
  • 1
  • 5
  • Would seem you are attempting to write to a directory you don't have permissions to, try a more complete string '~/Documents/births1880.csv' The exact string is somewhat operating system and configuration dependent. – dartdog Jun 19 '16 at 18:22
  • Thank you ! I am very new to this. I checked my current working directory, and I see I was pointed to the Anaconda directory that was running python. I fought with the shell to change my directory, and it won't let me pick the directory I want. I could change my directory up to the parent directory for Applications, however. And given that I could at least get myself there, that's where I dropped the CSV file. And it worked ! For now, I'm going to work from here. Thank you ! – Louis Flores Jun 19 '16 at 18:35

0 Answers0