python - xlsxwriter 条件格式 icon_set 中间值 = 0 未显示正确的箭头

标签 python python-3.x xlsxwriter

问题: 我想将使用 xlsx 的条件格式 icon_set 应用于列,但没有获得正确值的正确箭头

这是我想要的输出:

desired output

这是我当前的输出:

enter image description here

这是我的代码:

writer.sheets[sheet].conditional_format('J54:K200', {'type': 'icon_set',
                                                         'icon_style': '3_arrows',

                                                         'icons': [
                  {'criteria': '>=', 'type': 'number', 'value': 1},
                  {'criteria': '>=', 'type': 'number', 'value': 0},
                  {'criteria': '<', 'type': 'number', 'value': -1}

                                                         ]}
                                            )

这是我看过的:

除了这里的类似问题,这就是我所做的:

我查看了 Excel 的公式并与我自己的工作进行了比较,从我的输出开始,找出正确的规则。 到目前为止,我最接近的是,当我将图标 'value' 分别更改为 2、1、0 时,我得到 1 以具有中间的橙色箭头:

when the 1ns get the orange arrow

这告诉我我的相等性一定是正确的,但它并没有产生预期的结果。 感谢您提供的任何帮助!

最佳答案

如果您从代码中删除 {'criteria': '>=', 'type': 'number', 'value': 0}, 它应该可以正常工作。我在下面有一个具有预期输出的可重现示例。

import pandas as pd
import numpy as np

#Creating a sample dataframe for example demonstration
df = pd.DataFrame({'col1': [0, -1, 10, -2], 'col2': [-11, 0, -3, 1]})


writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1', index=False)

writer.sheets['Sheet1'].conditional_format('A2:B5', {'type': 'icon_set',
                                                         'icon_style': '3_arrows',
                                                         'icons': [
                  {'criteria': '>=', 'type': 'number', 'value': 0.001},
                  {'criteria': '<=', 'type': 'number', 'value': -0.001}
                                                         ]}
                                            )


writer.save()

预期的测试.xlsx:

Expected Output

关于python - xlsxwriter 条件格式 icon_set 中间值 = 0 未显示正确的箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50977697/

相关文章:

python - python中这一行表达式的解释

Python Pandas xlsxwriter 堆积折线图类型设置Excel中的标准折线图

python - xlsx writer - 如何仅在单元格的一侧获得粗边框?

c# - 安全和短的服务器-客户端连接

Python 调试器 (pdb) : Navigating through multi-module code using pdb

python - 如何在opencv 4.1.0中实现LSD

python - xlsxwriter worksheet.write_blank 适用于范围

python - 将项目添加到购物车 Django Python

python - 如何在python中对齐文本输出?

python - 如何重复 try-except block