Pandas to_excel将数据帧结果写入空白电子表格 - 如何使用xlwt写入excel?

时间:2016-07-18 13:46:02

标签: python pandas dataframe export-to-excel xlwt

编写数据框:

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电子表格,工作簿'Sheet1':

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文件或输出错误消息

任何帮助非常感谢

1 个答案:

答案 0 :(得分: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()