Pandas Style to Excel使用xlsxwriter作为引擎



我试图返回背景颜色和字体大小,但它只工作时,我只返回一个值,我的代码有什么问题?

这个行不通,我得到这个错误:

""" Format cells in Excel file and output to screen if on windows"""
color = 'red' if '>' in str(val) else 'lightgray'
font_size = '45px'
return f'font-size: {font_size} ,background-color: {color}'

但是如果我只返回一个它就可以工作fontsize或color

""" Format cells in Excel file and output to screen if on windows"""
color = 'red' if '>' in str(val) else 'lightgray'
font_size = '45px'
return f'font-size: {font_size}'

感谢您在高级Dini中的帮助

我不得不使用;而不是,(逗号)来传递任意多的参数。

""" Format cells in Excel file and output to screen if on windows"""
color = 'red' if '>' in str(val) else 'lightgray'
font_size = '45px'
return f'font-size: {font_size} ; background-color: {color}'

最新更新