I'm trying to style a value and a value next to it in a pandas dataframe:
pandas_chart_sorted = pd.DataFrame({'Palabras': {0: 'papa', 1: 'pepe', 2: 'ja'}, 'Apariciones': {0: 2, 1: 2, 2: 1}})
def filter_mark(val):
if val in self.filters:
color = 'red'
else:
color = 'black'
return 'color: {}'.format(color)
pandas_chart_sorted = pandas_chart_sorted.style.applymap(filter_mark)
with pd.ExcelWriter(self.new_path) as writer:
pandas_chart_sorted.to_excel(writer)
but I can't manage to style the value right next to it. So the output is this but it should look like this.
How can I do it?
Try this method:
Output: