## Description

I have a Pandas data frame `hours`, which I want to display (in a Quarto document rendered to HTML) such that values above 180 are red.

```python
hs = hours.style
hs.applymap(lambda value: 'color: red' if value > 180 else '')
```

This works, but in the process the nice default styling of data frames is lost: numbers have lots of unnecessary 0 decimals, columns are extremely narrow, the background is uniform white instead of alternating with gray.

I looked at the HTML code, and saw that in standard display of dataframes, the `table` element has the property `class="dataframe"`. So I added it:

```python
hs = hours.style
hs.set_table_attributes('class="dataframe"')
hs.applymap(lambda value: 'color: red' if value > 180 else '')
```

This is partially successful, the display looks decent, though not identical to the standard style.

However, the red coloring is gone.

I also tried

```python
hs = hours.style
hs.applymap(lambda value: 'color: red' if value > 180 else '')
hs.set_table_attributes('class="dataframe"')
```

but with the same outcome.

Finally, I followed the advice in a comment on https://stackoverflow.com/questions/71911644/pandas-styler-using-set-table-styles-along-with-applymap, to use `'color: red !important'`, again without effect.

Looking at the HTML code, it appears that `applymap` is implemented by inserting a `style` element directly before the table:

```html
<style type="text/css">
#T_1ad9f_row6_col2, #T_1ad9f_row9_col1, #T_1ad9f_row9_col2, #T_1ad9f_row45_col0, #T_1ad9f_row45_col2 {
  color: red !important;
}
</style>
<table id="T_1ad9f">
```

This element is omitted as soon as I use `set_table_attributes`.

## Minimal, fully reproducible example

``````markdown
---
jupyter: python3
---

create dataframe

```{python}
import pandas as pd
df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
```

nicely styled display

```{python}
df
```

highlighting numbers red removes the styling

```{python}
def mapfunction(value):
    if value > 4:
        return 'color: red'
    else:
        return ''
df.style.applymap(mapfunction)
```

trying to restore the styling removes the highlighting

```{python}
df.style.applymap(mapfunction).set_table_attributes('class="dataframe"')
```

regardless of the order

```{python}
df.style.set_table_attributes('class="dataframe"').applymap(mapfunction)
```
``````

## `quarto check`

``````

[✓] Checking Quarto installation......OK
      Version: 1.2.335
      Path: /opt/quarto/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.10.5 (Conda)
      Path: /home/ca/.conda/envs/std/bin/python3
      Jupyter: 4.10.0
      Kernels: python3, matlab, matlab_connect

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.0.4
      Path: /usr/lib/R
      LibPaths:
        - /home/ca/.local/lib/R
        - /usr/lib/R/site-library
        - /usr/lib/R/library
      rmarkdown: 2.11

[✓] Checking Knitr engine render......OK
``````

## Operating system

Debian GNU/Linux 11.6, kernel 5.10.0-21-amd64

## Checklist

- [X] Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [X] Please [format your issue](https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us) so it is easier for us to read the bug report.
- [ ] Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [X] Please document the operating system you're running. If on Linux, please provide the specific distribution.
- [X] Please provide the output of `quarto check` so we know which version of quarto and its dependencies you're running.
2023-04-06T18:54:41Z
allefeld
needs-repro
closed
set_table_attributes neutralizes applymap
https://github.com/quarto-dev/quarto-cli/issues/5117