diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 877e146fd8681..be748dfbdb2d6 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -466,7 +466,7 @@ def _translate(self): } colspan = col_lengths.get((r, c), 0) if colspan > 1: - es["attributes"] = [f'colspan="{colspan}"'] + es["attributes"] = f'colspan="{colspan}"' row_es.append(es) head.append(row_es) @@ -517,7 +517,7 @@ def _translate(self): } rowspan = idx_lengths.get((c, r), 0) if rowspan > 1: - es["attributes"] = [f'rowspan="{rowspan}"'] + es["attributes"] = f'rowspan="{rowspan}"' row_es.append(es) for c, col in enumerate(self.data.columns): @@ -529,6 +529,7 @@ def _translate(self): "value": value, "display_value": formatter(value), "is_visible": (c not in hidden_columns), + "attributes": "", } # only add an id if the cell has a style diff --git a/pandas/io/formats/templates/html.tpl b/pandas/io/formats/templates/html.tpl index b315c57a65cdf..65fc1dfbb37c4 100644 --- a/pandas/io/formats/templates/html.tpl +++ b/pandas/io/formats/templates/html.tpl @@ -39,7 +39,7 @@ {% for c in r %} {% if c.is_visible != False %} - <{{c.type}} class="{{c.class}}" {{c.attributes|join(" ")}}>{{c.value}} + <{{c.type}} class="{{c.class}}" {{c.attributes}}>{{c.value}} {% endif %} {% endfor %} @@ -56,7 +56,7 @@ {% for c in r %} {% if c.is_visible != False %} - <{{c.type}} {% if c.id is defined -%} id="T_{{uuid}}{{c.id}}" {%- endif %} class="{{c.class}}" {{c.attributes|join(" ")}}>{{c.display_value}} + <{{c.type}} {% if c.id is defined -%} id="T_{{uuid}}{{c.id}}" {%- endif %} class="{{c.class}}" {{c.attributes}}>{{c.display_value}} {% endif %} {% endfor %} diff --git a/pandas/tests/io/formats/test_style.py b/pandas/tests/io/formats/test_style.py index d134f33e15525..2a6505a43b80a 100644 --- a/pandas/tests/io/formats/test_style.py +++ b/pandas/tests/io/formats/test_style.py @@ -1323,7 +1323,7 @@ def test_mi_sparse(self): "display_value": "a", "is_visible": True, "type": "th", - "attributes": ['rowspan="2"'], + "attributes": 'rowspan="2"', "class": "row_heading level0 row0", "id": "level0_row0", }