@@ -281,7 +281,8 @@ def concat(self, other: Styler) -> Styler:
281281 ----------
282282 other : Styler
283283 The other Styler object which has already been styled and formatted. The
284- data for this Styler must have the same columns as the original.
284+ data for this Styler must have the same columns as the original, and the
285+ number of index levels must also be the same to render correctly.
285286
286287 Returns
287288 -------
@@ -344,11 +345,24 @@ def concat(self, other: Styler) -> Styler:
344345 >>> styler.concat(other) # doctest: +SKIP
345346
346347 .. figure:: ../../_static/style/footer_extended.png
348+
349+ When ``other`` has fewer index levels than the original Styler it is possible
350+ to extend the index in ``other``, with placeholder levels.
351+
352+ >>> df = DataFrame([[1], [2]], index=pd.MultiIndex.from_product([[0], [1, 2]]))
353+ >>> descriptors = df.agg(["sum"])
354+ >>> descriptors.index = pd.MultiIndex.from_product([[""], descriptors.index])
355+ >>> df.style.concat(descriptors.style) # doctest: +SKIP
347356 """
348357 if not isinstance (other , Styler ):
349358 raise TypeError ("`other` must be of type `Styler`" )
350359 if not self .data .columns .equals (other .data .columns ):
351360 raise ValueError ("`other.data` must have same columns as `Styler.data`" )
361+ if not self .data .index .nlevels == other .data .index .nlevels :
362+ raise ValueError (
363+ "number of index levels must be same in `other` "
364+ "as in `Styler`. See documentation for suggestions."
365+ )
352366 self .concatenated = other
353367 return self
354368
0 commit comments