原文链接:http://www.juzicode.com/archives/3127
错误提示:
在pandas中用to_excel()写文件提示:ModuleNotFoundError: No module named ‘xlwt’:
import numpy as np
import pandas as pd
arr = np.random.randint(-50,50,size=(3,10))
ind = [x for x in range(3)]
columns = list('ABCDEFGHIJ')
df = pd.DataFrame(arr,index=ind,columns=columns)
print('df=\n',df)
df.to_excel('pd-test-w.xls')
print('df=\n',df)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-22-6c38b222d559> in <module>
6 df = pd.DataFrame(arr,index=ind,columns=columns)
7 print('df=\n',df)
----> 8 df.to_excel('pd-test-w.xls')
9 print('df=\n',df)
d:\python\python38\lib\site-packages\pandas\core\generic.py in to_excel(self, excel_writer, sheet_name, na_rep, float_format,

博客指出在pandas中使用to_excel()写文件时,出现ModuleNotFoundError: No module named ‘xlwt’错误。原因是pip安装pandas时不会自动安装xlwt依赖,需手动安装。解决办法是用pip手动安装xlwt模块。
最低0.47元/天 解锁文章
2233

被折叠的 条评论
为什么被折叠?



