欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

pandas写入excel提示FutureWarning: As the xlwt package is no longer maintained

程序员文章站 2022-05-30 09:59:19
...

 

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')就可以了。

相关标签: python excel