2016-07-18 55 views
2

寫數據幀:熊貓to_excel寫入數據幀結果空白的電子表格 - 如何使用xlwt寫入excel?

New_DF = 
      caviae species murliniae freundii braakii freundii cloacae \ 
15368485  NaN  NaN  NaN  NaN  NaN  NaN  NaN 
15368486  NaN  NaN  NaN   1  NaN   1  NaN 
15368487  NaN  NaN  NaN  NaN  NaN  NaN  NaN 
15368488  NaN  NaN  NaN  NaN  NaN  NaN  NaN 
15368489  NaN  1  NaN  NaN  NaN  NaN  NaN 

等 到的.xls電子表格中,工作簿 'Sheet 1中':

import StringIO 
import pandas as pd 
import xlwt 

New_DF = pd.DataFrame(SpeciesCount,labNo,Species) 

xlwt_writer = pd.io.excel.get_writer('xlwt') 

my_writer = xlwt_writer('C:\Users\Georgina\Documents\Test\1291707 STS Excel Extract.xls') 

xl_out = StringIO.StringIO() 
my_writer.path = xl_out 
New_DF.to_excel(my_writer,sheet_name='Sheet1',startrow = 4) 
my_writer.save() 

這不會改變.xls文件或輸出錯誤消息

任何幫助太多讚賞

+0

'xl_out'應該做什麼?這可能是空的,並將xlwt_writer的路徑重置爲無或空字符串。 – miraculixx

+0

我從閱讀各種其他幫助頁面:http://stackoverflow.com/questions/28058563/write-to-stringio-object-using-pandas-excelwriter我已經將xl_out更改爲文件所在的路徑&現在它有一個my_writer.save()行的問題。它給了我錯誤:「in save f = open(file_name_or_filelike_obj,'w + b') IOError:[Errno 13] Permission denied:'C:\\ Users \\ Georgina \\ Documents \\ Software Development \\ Bacti評論自動排序'「 –

+0

我有根據windows exporer該目錄的權限 –

回答

0

試試這個:

import StringIO 
import pandas as pd 
import xlwt 

New_DF = pd.DataFrame(SpeciesCount,labNo,Species) 

writer = pd.ExcelWriter('C:\Users\Georgina\Documents\Test\1291707 STS Excel Extract.xls', engine='xlwt') 
New_DF.to_excel(writer, sheet_name='Sheet1', startrow = 4) 
writer.save()