2
尝试此样式器对象转换为XLSX表:MetaSerialisable对象参数后,**必须是一个映射,不是Unicode
avg.style.background_gradient(cmap='RdYlGn',low=.09,high=.18,axis=1).to_excel('test.xlsx',engine='xlsxwriter')
但是,我得到的错误:
TypeError: MetaSerialisable object argument after ** must be a mapping, not unicode
当我尝试:
avg.style.background_gradient({'cmap':'RdYlGn'},low=.09,high=.18,axis=1).to_excel('test.xlsx',engine='xlsxwriter')
TypeError: ("unhashable type: 'dict'", u'occurred at index (Gain/Expsr%, 5)')
有了这一个在这里,这里还有没有背景渐变输出:
writer = pd.ExcelWriter('usher.xlsx')
df.style.background_gradient(cmap='RdYlGn').to_excel(writer,engine='openpyxl')
writer.save()
做,如果你忽略'to_excel()'一部分,你得到同样的错误? – jmcnamara
@jmcnamara不能,样式器对象工作正常 –
好的。从Pandas [Styler](http://pandas.pydata.org/pandas-docs/stable/style.html)文档看来,'background_gradient'看起来只能在Html输出中被支持。即使如此,只有使用'openpyxl'作为Excel引擎才支持'to_excel()'支持的样式。 – jmcnamara