From aeacf155df253c2d2a02815f5840c66911526918 Mon Sep 17 00:00:00 2001 From: vijayant Date: Fri, 11 Oct 2019 09:17:18 -0700 Subject: [PATCH] ENH: Support for specifying col names for col_space --- pandas/core/frame.py | 2 ++ pandas/io/formats/format.py | 2 ++ pandas/io/formats/html.py | 7 ++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 5200ad0ba0d23..e9878692784d9 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2188,6 +2188,7 @@ def to_html( buf=None, columns=None, col_space=None, + col_space_cols=None, header=True, index=True, na_rep="NaN", @@ -2244,6 +2245,7 @@ def to_html( self, columns=columns, col_space=col_space, + col_space_cols=col_space_cols, na_rep=na_rep, formatters=formatters, float_format=float_format, diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index ad62c56a337b6..40b7d68595804 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -533,6 +533,7 @@ def __init__( frame: "DataFrame", columns: Optional[Sequence[str]] = None, col_space: Optional[Union[str, int]] = None, + col_space_cols: Optional[Sequence[str]] = None, header: Union[bool, Sequence[str]] = True, index: bool = True, na_rep: str = "NaN", @@ -575,6 +576,7 @@ def __init__( self.na_rep = na_rep self.decimal = decimal self.col_space = col_space + self.col_space_cols = col_space_cols self.header = header self.index = index self.line_width = line_width diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 50fa4796f8d72..999e28828f9b4 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -100,7 +100,7 @@ def write_th( self, s: Any, header: bool = False, indent: int = 0, tags: Optional[str] = None ) -> None: """ - Method for writting a formatted cell. + Method for writing a formatted cell. If col_space is set on the formatter then that is used for the value of min-width. @@ -122,8 +122,9 @@ def write_th( A written cell. """ if header and self.fmt.col_space is not None: - tags = tags or "" - tags += 'style="min-width: {colspace};"'.format(colspace=self.fmt.col_space) + if self.fmt.col_space_cols is None or s in self.fmt.col_space_cols: + tags = tags or "" + tags += 'style="min-width: {colspace};"'.format(colspace=self.fmt.col_space) self._write_cell(s, kind="th", indent=indent, tags=tags)