Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created January 3, 2022 07:17
Show Gist options
  • Save kshirsagarsiddharth/0e5bfe3e9d22ffc28f4a58f18019cd34 to your computer and use it in GitHub Desktop.
Save kshirsagarsiddharth/0e5bfe3e9d22ffc28f4a58f18019cd34 to your computer and use it in GitHub Desktop.
## Highliting losses in the dataframe
def color_negative_values(value):
"""
This function takes in values of dataframe
if particular value is negative it is colored as redwhich implies loss
if value is greater than one it implies higher profit
"""
if value < 0:
color = '#ff8a8a'
elif value > 1:
color = '#4fc277'
else:
color = 'black'
return f"color: {color}"
companies_returns.style.applymap(color_negative_values)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment