import pandas

data=pandas.DataFrame({
    'id':[1,2,3],
    'name':['user','admin','nothing'],
    'age':[18,20,11],
    'city':['北京','上海','深圳']
})
data=data.set_index('id')
print(data)

data.to_excel('1.xls')
print('write done!')

./pandas_test.py:16: FutureWarning: As the xlwt package is no longer maintained, the xlwt engine will be removed in a future version of pandas. This is the only engine in pandas that supports writing in the xls format. Install openpyxl and write to an xlsx file instead. You can set the option io.excel.xls.writer to 'xlwt' to silence this warning. While this option is deprecated and will also raise a warning, it can be globally set and the warning suppressed.
  data.to_excel('1.xls')

由于xlwt软件包不再维护,xlwt引擎将在未来版本的pandas中删除。这是pandas中唯一支持xls格式写入的引擎。安装openpyxl并改为写入xlsx文件。您可以设置选项io.excel.xls文件。写入“xlwt”以消除此警告。虽然此选项已弃用,并且还会引发警告,但可以全局设置它并抑制警告

将data.to_excel('1.xls')改为data.to_excel('1.xlsx')就可以了。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐