1

I am trying to use my highlight_diff function to compare two dataframes and highlight the differences in a HTML. The problem occurs at output to html. I read in another post that someone was successful getting formatting to apply to a written html by using the Pandas styler. The styler forms the table correctly, but I want to add table borders as well. Can anyone point me in the right direction?

def highlight_diff(data, color='yellow'):
        attr = 'background-color: {}'.format(color)
        other = data.xs('Old', axis='columns', level=0)
        return pd.DataFrame(np.where(data.ne(other, level=-1), attr, ''),
                            index=data.index, columns=data.columns)
html=dfs.style.apply(highlight_diff, axis=None).render()
#I have tried:
#dfs.style.set_table_styles([{'selector': 'th, td', 'props': [('border', '1px solid black'), 
                                # ('padding', '4px'), 
                                # ('text-align', 'center')]}])
with open(fname, 'w', encoding='utf-8') as myFile:
        myFile.write(html)
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Tyler Russell
  • 653
  • 3
  • 10
  • 26

0 Answers0