Reputation: 4250
When I run applymap() in a Jupyter cell, it works fine. However, when I run the exact same code inside of my class, it doesn't style the DataFrame.
#get the DataFrame from the class in the Jupyter cell
df = my_class.quality('headers')
# applymap() styles the table outside the class as expected
df.style.applymap(my_class.quality_style_null_val)
#functions in my_class
def quality(self, key=None):
df = self.df(key)
df.style.applymap(self.test)
return df
def test(val, params={'background-color':'green', "color":'white'}):
return 'color: red'
#instantiate my_class and call function:
df = my_class.quality('headers')
Upvotes: 0
Views: 460
Reputation: 4250
It works when you return the df.applymap() instead of styling and then returning.
def quality(self, key):
df = unify.df(key)
return df.style.applymap(self.quality_style)
Upvotes: 3