簡體   English   中英

使用 xlsxwriter 作為引擎將 Pandas 樣式轉換為 Excel

[英]Pandas Style to Excel using xlsxwriter as engine

我正在嘗試返回背景顏色和字體大小,但它僅在我只返回一個值時才有效,我的代碼有什么問題?

這個不行,我得到這個錯誤:

""" 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 的幫助

我不得不使用; 而不是 ,(comma) 來傳遞我想要的盡可能多的參數。

""" 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}'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM