import pandas as pd
import colored
test = pd.DataFrame(['foo;bar;baz', 'foo', 'bar', 'baz'])
mk = lambda s: colored.bg('red') + s + colored.bg(255) if s in {'bar', } else s
mark = lambda s: ';'.join(map(mk, s.split(';')))
for i, t in test.iterrows():
print(';'.join(map(mark, t[0].split(';'))))
print(test.applymap(mark))
display(test.style.applymap(mark))
问题是,如果我对我正在使用的实际数据集使用打印语句,则文本将被截断。是否可以使用display
函数中的多种颜色?我会使用数据帧的style
属性,但据我所知,这只会突出显示整个单元格,而不是其中一部分。