Code Sample, a copy-pastable example if possible
# Your code here
# the code is from the example of styling with a little modification(add a rasie in function highlight_max, to see if the function is called or not(the result is NOT)
# https://pandas.pydata.org/pandas-docs/stable/style.html
import pandas as pd
import numpy as np
np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
axis=1)
df.iloc[0, 2] = np.nan
def highlight_max(s):
raise ##### try to RAISE a exception here
'''
highlight the maximum in a Series yellow.
'''
is_max = s == s.max()
return ['background-color: yellow' if v else '' for v in is_max]
df.style.apply(highlight_max)
display(df)
display(pd.__version__)
Problem description
The minimal example showd the styling callback function is not called(no raise happened)
Expected Output
raise an exception in styling function, but actually NOT(not executed the function)
Output of pd.show_versions()
0.21.0
Comment From: TomAugspurger
You need to render it.
df.style.apply(highlight_max).render()
_repr_html_
calls render implicitly.
Comment From: xuboying
@TomAugspurger
FYI Not sure what happens, but finally I got the reasult with HTML function and rander call(which you pointed out).
from IPython.display import display, HTML
display(HTML(df.style.apply(highlight_max).render()))
without HTML, I'll see html source code on notebook.