我收到此错误:ImportError: No module named style
,来自此导入语句:from openpyxl.style import Style
以下是与数据透视表相关的代码:
excel = pd.ExcelFile(filename)
df = excel.parse(sheetname=0)
df1 = df[['Product Description', 'Supervisor']]
print df1
table1 = pd.pivot_table(df1, rows = ['Supervisor'],
cols = ['Product Description'],
values = ['Product Description'],
aggfunc = [lambda x: len(x)], fill_value = 0)
writer = pd.ExcelWriter(filename)
table1.to_excel(writer, 'Pivot Table')
writer.save()
workbook.save(filename)
我唯一可以想到的可能是它会导致Supervisor列的标题应用了一个样式(这只是对单词' Supervisor'应用粗体样式)。删除应用样式的行并不能解决问题。
supervisorheader = worksheet.cell("CV1")
s = Style(font=Font(bold=True))
supervisorheader.style = s
以下是我的数据框:
Product Description Supervisor
0 EXPRESS 12:00 (doc) Gordon
1 EXPRESS 10:30 (nondoc) Vinny P
2 EXPRESS 12:00 (doc) Vinny A
3 EXPRESS 12:00 (nondoc) Building
4 EXPRESS 12:00 (nondoc) Building
5 EXPRESS 12:00 (nondoc) Building
6 EXPRESS 12:00 (nondoc) Gordon
7 MEDICAL EXPRESS (nondoc) Gordon
8 EXPRESS 10:30 (nondoc) Vinny A
9 EXPRESS 12:00 (doc) Pete
10 EXPRESS 12:00 (nondoc) Vinny P
11 EXPRESS 10:30 (nondoc) Building
12 EXPRESS 12:00 (nondoc) Gordon
13 EXPRESS 12:00 (nondoc) Vinny A
14 EXPRESS 12:00 (nondoc) Building
15 EXPRESS 10:30 (doc) Gordon
[16 rows x 2 columns]
这是错误追溯:
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/harrisonleggio/tdx.py", line 34, in upload
return process(f.filename)
File "/home/harrisonleggio/tdx.py", line 201, in process
table1.to_excel(writer, 'Pivot Table', engine = 'xlsxwriter')
File "/usr/lib/python2.7/dist-packages/pandas/core/frame.py", line 1204, in to_excel
startrow=startrow, startcol=startcol)
File "/usr/lib/python2.7/dist-packages/pandas/io/excel.py", line 530, in write_cells
style = self._convert_to_style(cell.style)
File "/usr/lib/python2.7/dist-packages/pandas/io/excel.py", line 577, in _convert_to_style
from openpyxl.style import Style
ImportError: No module named style