Skip to content

Instantly share code, notes, and snippets.

@joonro
Created March 31, 2019 18:13
Show Gist options
  • Select an option

  • Save joonro/b67fd426dbc9dc7d7be151606247f0af to your computer and use it in GitHub Desktop.

Select an option

Save joonro/b67fd426dbc9dc7d7be151606247f0af to your computer and use it in GitHub Desktop.
[statsmodels highlight significant variables in result table] Highlight significant variables in result table using pandas.DataFrame.style #python #pandas #statsmodels
def highlight_row(row):
"""Highlight row with red color for variables with p < 0.05"""
color = ''
if row['P>|t|'] < 0.05:
color = 'red'
return ['color: %s' % color] * len(row.values)
df_result.style.apply(custom_style, axis=1).to_excel('results.xlsx')
df_result.style.apply(custom_style, axis=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment