@@ -1132,6 +1132,8 @@ def _copy(self, deepcopy: bool = False) -> Styler:
11321132 shallow = [ # simple string or boolean immutables
11331133 "hide_index_" ,
11341134 "hide_columns_" ,
1135+ "hide_column_names" ,
1136+ "hide_index_names" ,
11351137 "table_attributes" ,
11361138 "cell_ids" ,
11371139 "caption" ,
@@ -2042,6 +2044,7 @@ def hide_index(
20422044 self ,
20432045 subset : Subset | None = None ,
20442046 level : Level | list [Level ] | None = None ,
2047+ names : bool = False ,
20452048 ) -> Styler :
20462049 """
20472050 Hide the entire index, or specific keys in the index from rendering.
@@ -2065,6 +2068,11 @@ def hide_index(
20652068 The level(s) to hide in a MultiIndex if hiding the entire index. Cannot be
20662069 used simultaneously with ``subset``.
20672070
2071+ .. versionadded:: 1.4.0
2072+ names : bool
2073+ Whether to hide the index name(s), in the case the index or part of it
2074+ remains visible.
2075+
20682076 .. versionadded:: 1.4.0
20692077
20702078 Returns
@@ -2118,7 +2126,7 @@ def hide_index(
21182126
21192127 Hide a specific level:
21202128
2121- >>> df.style.format("{:,.1f").hide_index(level=1) # doctest: +SKIP
2129+ >>> df.style.format("{:,.1f} ").hide_index(level=1) # doctest: +SKIP
21222130 x y
21232131 a b c a b c
21242132 x 0.1 0.0 0.4 1.3 0.6 -1.4
@@ -2127,11 +2135,29 @@ def hide_index(
21272135 y 0.4 1.0 -0.2 -0.8 -1.2 1.1
21282136 -0.6 1.2 1.8 1.9 0.3 0.3
21292137 0.8 0.5 -0.3 1.2 2.2 -0.8
2138+
2139+ Hiding just the index level names:
2140+
2141+ >>> df.index.names = ["lev0", "lev1"]
2142+ >>> df.style.format("{:,.1f}").hide_index(names=True) # doctest: +SKIP
2143+ x y
2144+ a b c a b c
2145+ x a 0.1 0.0 0.4 1.3 0.6 -1.4
2146+ b 0.7 1.0 1.3 1.5 -0.0 -0.2
2147+ c 1.4 -0.8 1.6 -0.2 -0.4 -0.3
2148+ y a 0.4 1.0 -0.2 -0.8 -1.2 1.1
2149+ b -0.6 1.2 1.8 1.9 0.3 0.3
2150+ c 0.8 0.5 -0.3 1.2 2.2 -0.8
21302151 """
21312152 if level is not None and subset is not None :
21322153 raise ValueError ("`subset` and `level` cannot be passed simultaneously" )
21332154
21342155 if subset is None :
2156+ if level is None and names :
2157+ # this combination implies user shows the index and hides just names
2158+ self .hide_index_names = True
2159+ return self
2160+
21352161 levels_ = _refactor_levels (level , self .index )
21362162 self .hide_index_ = [
21372163 True if lev in levels_ else False for lev in range (self .index .nlevels )
@@ -2144,12 +2170,16 @@ def hide_index(
21442170 # error: Incompatible types in assignment (expression has type
21452171 # "ndarray", variable has type "Sequence[int]")
21462172 self .hidden_rows = hrows # type: ignore[assignment]
2173+
2174+ if names :
2175+ self .hide_index_names = True
21472176 return self
21482177
21492178 def hide_columns (
21502179 self ,
21512180 subset : Subset | None = None ,
21522181 level : Level | list [Level ] | None = None ,
2182+ names : bool = False ,
21532183 ) -> Styler :
21542184 """
21552185 Hide the column headers or specific keys in the columns from rendering.
@@ -2173,6 +2203,11 @@ def hide_columns(
21732203 The level(s) to hide in a MultiIndex if hiding the entire column headers
21742204 row. Cannot be used simultaneously with ``subset``.
21752205
2206+ .. versionadded:: 1.4.0
2207+ names : bool
2208+ Whether to hide the column index name(s), in the case all column headers,
2209+ or some levels, are visible.
2210+
21762211 .. versionadded:: 1.4.0
21772212
21782213 Returns
@@ -2239,11 +2274,29 @@ def hide_columns(
22392274 y a 0.4 1.0 -0.2 -0.8 -1.2 1.1
22402275 b -0.6 1.2 1.8 1.9 0.3 0.3
22412276 c 0.8 0.5 -0.3 1.2 2.2 -0.8
2277+
2278+ Hiding just the column level names:
2279+
2280+ >>> df.columns.names = ["lev0", "lev1"]
2281+ >>> df.style.format("{:.1f").hide_columns(names=True) # doctest: +SKIP
2282+ x y
2283+ a b c a b c
2284+ x a 0.1 0.0 0.4 1.3 0.6 -1.4
2285+ b 0.7 1.0 1.3 1.5 -0.0 -0.2
2286+ c 1.4 -0.8 1.6 -0.2 -0.4 -0.3
2287+ y a 0.4 1.0 -0.2 -0.8 -1.2 1.1
2288+ b -0.6 1.2 1.8 1.9 0.3 0.3
2289+ c 0.8 0.5 -0.3 1.2 2.2 -0.8
22422290 """
22432291 if level is not None and subset is not None :
22442292 raise ValueError ("`subset` and `level` cannot be passed simultaneously" )
22452293
22462294 if subset is None :
2295+ if level is None and names :
2296+ # this combination implies user shows the column headers but hides names
2297+ self .hide_column_names = True
2298+ return self
2299+
22472300 levels_ = _refactor_levels (level , self .columns )
22482301 self .hide_columns_ = [
22492302 True if lev in levels_ else False for lev in range (self .columns .nlevels )
@@ -2256,6 +2309,9 @@ def hide_columns(
22562309 # error: Incompatible types in assignment (expression has type
22572310 # "ndarray", variable has type "Sequence[int]")
22582311 self .hidden_columns = hcols # type: ignore[assignment]
2312+
2313+ if names :
2314+ self .hide_column_names = True
22592315 return self
22602316
22612317 # -----------------------------------------------------------------------
0 commit comments