From ad98e6b737f295362b33e2f8efa31f790e1d662d Mon Sep 17 00:00:00 2001 From: SRIRAM777 Date: Sun, 13 Oct 2019 09:31:36 +0530 Subject: [PATCH] Fix for col_space parameter for multiple columns DataFrame.to_html col_space parameter to change width of a specific column only --- pandas/io/formats/format.py | 2 +- pandas/io/formats/html.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index ad62c56a337b6..b5c95a0465340 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -532,7 +532,7 @@ def __init__( self, frame: "DataFrame", columns: Optional[Sequence[str]] = None, - col_space: Optional[Union[str, int]] = None, + col_space: Optional[Union[dict, str, int]] = None, header: Union[bool, Sequence[str]] = True, index: bool = True, na_rep: str = "NaN", diff --git a/pandas/io/formats/html.py b/pandas/io/formats/html.py index 50fa4796f8d72..aa74daf94d530 100644 --- a/pandas/io/formats/html.py +++ b/pandas/io/formats/html.py @@ -123,7 +123,11 @@ def write_th( """ 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 type(self.fmt.col_space) is dict: + if s in self.fmt.col_space: + tags += 'style="min-width: {colspace};"'.format(colspace=self.fmt.col_space[s]) + else: + tags += 'style="min-width: {colspace};"'.format(colspace=self.fmt.col_space) self._write_cell(s, kind="th", indent=indent, tags=tags)