我试图根据df中的一列的值为其着色。我只尝试了一个值,但没有得到任何颜色的结果。这是我的密码
writer = pd.ExcelWriter('resultcolored.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet')
workbook = writer.book
worksheet = writer.sheets["Sheet"]
format = workbook.add_format({'bg_color': '#C6EFCE',
'font_color': '#006100'})
worksheet.conditional_format( 'AJ1:AJ10',
{ 'type': 'text',
'criteria': 'containing',
'value': 'Direct',
'format': format
}
)
writer.save()
它保存文件,但不删除任何值。你能帮帮我吗
它应该像预期的那样工作。以下是基于您的代码的工作示例:
输出:
相关问题 更多 >
编程相关推荐