[英]Compare row value with column name and highlight the intersecting cell in Pandas
I have a dataset like this and i want to highlight the intersecting cell based on the date1 and date2 value in a row and the corresponding column name input dataset我有一个这样的数据集,我想根据一行中的 date1 和 date2 值以及相应的列名输入数据集突出显示相交的单元格
My comment was actually incorrect.我的评论实际上是不正确的。 Pandas does offer conditional formatting / conditional styling for output in Jupyter notebooks.
Pandas确实为 Jupyter 笔记本中的 output 提供条件格式/条件样式。 The documentation is here: https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html
文档在这里: https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html
There are actually several ways to implement this, but the simplest way is to check the value of, and set the style for, each individual cell.实际上有几种方法可以实现这一点,但最简单的方法是检查每个单独单元格的值并设置其样式。
data = pd.DataFrame({
'x': [1, 2, 3, 4],
'y': [19, 10, 11, 12]
})
def yellow_highlight_max(series):
is_max_val = series == series.max()
return is_max_val.map({True: 'background-color: yellow', False: ''}).tolist()
data.style.apply(yellow_highlight_max)
You should carefully consult the documentation for your desired usage.您应该仔细查阅文档以了解您想要的用途。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.