Given the following DataFrame and list of cells to highlight:
import pandas as pd
import numpy as np
# Example DF
df = pd.DataFrame(
np.random.randint(0, 100, size=(10, 10)),
columns=list('ABCDEFGHIJ')
)
cells_to_highlight = [
(1, 'B'),
(3, 'C'),
(5, 'G'),
(2, 'E')
]
How can I output a DataFrame with only those particular cells highlighted?
I know I can pass the position of a single cell to .style.applymap()
to highlight it as such:
# Style the DF
(
df
.style
.applymap(lambda x: "background-color: yellow", subset=cells_to_highlight[0])
)
But how can I pass multiple cells to this method?