I have a dataFrame with 6 columns. And I want to do conditional formatting on two columns of them. So my dataFrame looks like this
And I want to highlight duplicate values from College and College_F2 columns. After which my dataframe will look like this
The code written for this looks like this: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)
And the error this code is giving to me is
ValueError: Shape of passed values is (6, 6), indices imply (6, 2)
IDE that I am using is PyCharm. How to resolve this issue?
Thanks in advance.