ipython - Problems writing to Excel in pandas -


have following annoying problem ipython script using to_excel function in pandas: @ end of script want write results excel file. if include path e.g "~/", script breaks down enclosed error messages. if input file name script runs , produce new file in current folder. bug or doing wrong? code follows:

path=dir+file_name print "writing %s " % path opt_design.to_excel(path, sheet_name='sheet1',index=false) print "finished!"`` 

the runtime error is:

--------------------------------------------------------------------------- ioerror                                   traceback (most recent call last) <ipython-input-1-b9e6707b5b6c> in <module>()  43 path=dir+file_name  44 print "writing %s " % path ---> 45 opt_design.to_excel(path, sheet_name='sheet1',index=false)  46 print "finished!"  47  

/library/python/2.7/site-packages/pandas-0.11.1.dev_fcced51_20130617-py2.7-macosx-10.8- intel.egg/pandas/core/frame.pyc in to_excel(self, excel_writer, sheet_name, na_rep, float_format, cols, header, index, index_label, startrow, startcol)

1494                                  startrow=startrow, startcol=startcol) 1495         if need_save: -> 1496             excel_writer.save() 1497  1498     def to_stata(self, fname, convert_dates=none, write_index=true, encoding="latin-1", 

/library/python/2.7/site-packages/pandas-0.11.1.dev_fcced51_20130617-py2.7-macosx-10.8-intel.egg/pandas/io/excel.pyc in save(self)

 351         save workbook disk  352         """  --> 353         self.book.save(self.path)  354   355     def write_cells(self, cells, sheet_name=none, startrow=0, startcol=0): 

/usr/local/cellar/python/2.7.5/frameworks/python.framework/versions/2.7/lib/python2.7/site-packages/openpyxl/workbook.pyc in save(self, filename)

 212             save_dump(self, filename)  213         else:  --> 214             save_workbook(self, filename) 

/usr/local/cellar/python/2.7.5/frameworks/python.framework/versions/2.7/lib/python2.7/site-packages/openpyxl/writer/excel.pyc in save_workbook(workbook, filename)

 153     """  154     writer = excelwriter(workbook)  --> 155     writer.save(filename)  156     return true  157  

/usr/local/cellar/python/2.7.5/frameworks/python.framework/versions/2.7/lib/python2.7/site-packages/openpyxl/writer/excel.pyc in save(self, filename)

 135     def save(self, filename):  136         """write data archive."""  --> 137         archive = zipfile(filename, 'w', zip_deflated)  138         self.write_data(archive)  139         archive.close() 

/usr/local/cellar/python/2.7.5/frameworks/python.framework/versions/2.7/lib/python2.7/zipfile.pyc in init(self, file, mode, compression, allowzip64)

 750             modedict = {'r' : 'rb', 'w': 'wb', 'a' : 'r+b'}  751             try:  --> 752                 self.fp = open(file, modedict[mode])  753             except ioerror:  754                 if mode == 'a': 

ioerror: [errno 2] no such file or directory: '~/cloudstation/test1.xlsx'

python doesn't expand home directory you. have couple of options:

  1. os.path.expanduser(the_path)
  2. os.path.join(os.environ.get('home'), the_path)

here's example

in [17]: os.path.expanduser('~/a_path_wth_tilde') out[17]: '/home/phillip/a_path_wth_tilde' 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -