我有一个 6 列的数据框。我想对其中的两列进行条件格式化。所以我的数据框看起来像这样
我想突出显示 College 和 College_F2 列中的重复值。之后我的数据框将如下所示
为此编写的代码如下所示:dataFrame_file = pd.read_excel(util.comcastFile2Path(), sheet_name='Sheet1')
def dummy_color(x):
c1 = 'background-color:red'
c2 = ''
cond = dataFrame_file.stack().duplicated(keep=False).unstack()
df1 = pd.DataFrame(np.where(cond, c1, c2), columns=x.columns, index=x.index)
return df1
dataFrame_file.style.apply(dummy_color,axis=None,subset=['College', 'College_F2']).to_excel(util.comcastFile2Path)
这段代码给我的错误是
ValueError: Shape of passed values is (6, 6), indices imply (6, 2)
我使用的 IDE 是 PyCharm。如何解决这个问题?
提前致谢。