Skip to content

Instantly share code, notes, and snippets.

@dardanxhymshiti
Last active April 12, 2022 17:11
Show Gist options
  • Save dardanxhymshiti/729f966740ace7579711186356b73920 to your computer and use it in GitHub Desktop.
Save dardanxhymshiti/729f966740ace7579711186356b73920 to your computer and use it in GitHub Desktop.
def highlight_columns(df, rows=20, color='lightgreen', columns_to_shadow=[], columns_to_show=[]):
highlight = lambda slice_of_df: 'background-color: %s' % color
sample_df = df.head(rows)
if len(columns_to_show) != 0:
sample_df = sample_df[columns_to_show]
highlighted_df = sample_df.style.applymap(highlight, subset=pd.IndexSlice[:, columns_to_shadow])
return highlighted_df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment