0

I have list of words which needs to be colored if they are appearing in a string in pandas print option in Jupyter

import pandas as pd
words=['bullish','bearish','day trading','loss']
df1=pd.DataFrame([[1,'Todays market was bearish and 20 accounts were in loss'],[2,'240 accounts did day trading in bullish market']],columns=['Row', 'Text'])

I need to color only Bearish & loss in the first text,bullish & Day trading in the second text

Todays market was bearish and 20 accounts were in loss

240 accounts did day trading in bullish market

asaha
  • 53
  • 5
  • https://stackoverflow.com/questions/49961211/python-pandas-highlight-matching-text-and-row shows how to use styler to change the background of the cells. Individual words are not supported unless you go into the individual HTML and reparse it. – Paul Brennan Dec 02 '20 at 10:36
  • It changes the entire cell color,I want to color only those specific words not the entire string. – asaha Dec 02 '20 at 15:05
  • that is the point unless you go and put the dataframe into HTML and then reparse it there is no clean way to do this in the current pandas functionality. – Paul Brennan Dec 02 '20 at 15:49
  • Thanks Paul, understood. – asaha Dec 02 '20 at 19:21

0 Answers0