A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pandas.pydata.org/docs/dev/reference/api/pandas.io.formats.style.Styler.hide.html below:

pandas.io.formats.style.Styler.hide — pandas 3.0.0.dev0+2320.g2547ff324a documentation

pandas.io.formats.style.Styler.hide#
Styler.hide(subset=None, axis=0, level=None, names=False)[source]#

Hide the entire index / column headers, or specific rows / columns from display.

Added in version 1.4.0.

Parameters:
subsetlabel, array-like, IndexSlice, optional

A valid 1d input or single key along the axis within DataFrame.loc[<subset>, :] or DataFrame.loc[:, <subset>] depending upon axis, to limit data to select hidden rows / columns.

axis{“index”, 0, “columns”, 1}

Apply to the index or columns.

levelint, str, list

The level(s) to hide in a MultiIndex if hiding the entire index / column headers. Cannot be used simultaneously with subset.

namesbool

Whether to hide the level name(s) of the index / columns headers in the case it (or at least one the levels) remains visible.

Returns:
Styler

Instance of class with specified headers/rows/columns hidden from display.

See also

Styler.apply

Apply a CSS-styling function column-wise, row-wise, or table-wise.

Styler.map

Apply a CSS-styling function elementwise.

Notes

Warning

This method only works with the output methods to_html, to_string and to_latex.

Other output methods, including to_excel, ignore this hiding method and will display all data.

This method has multiple functionality depending upon the combination of the subset, level and names arguments (see examples). The axis argument is used only to control whether the method is applied to row or column headers:

Note this method only hides the identified elements so can be chained to hide multiple elements in sequence.

Examples

Simple application hiding specific rows:

>>> df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], index=["a", "b", "c"])
>>> df.style.hide(["a", "b"])
     0    1
c    5    6

Hide the index and retain the data values:

>>> midx = pd.MultiIndex.from_product([["x", "y"], ["a", "b", "c"]])
>>> df = pd.DataFrame(np.random.randn(6, 6), index=midx, columns=midx)
>>> df.style.format("{:.1f}").hide()
                 x                    y
   a      b      c      a      b      c
 0.1    0.0    0.4    1.3    0.6   -1.4
 0.7    1.0    1.3    1.5   -0.0   -0.2
 1.4   -0.8    1.6   -0.2   -0.4   -0.3
 0.4    1.0   -0.2   -0.8   -1.2    1.1
-0.6    1.2    1.8    1.9    0.3    0.3
 0.8    0.5   -0.3    1.2    2.2   -0.8

Hide specific rows in a MultiIndex but retain the index:

>>> df.style.format("{:.1f}").hide(subset=(slice(None), ["a", "c"]))
...
                         x                    y
           a      b      c      a      b      c
x   b    0.7    1.0    1.3    1.5   -0.0   -0.2
y   b   -0.6    1.2    1.8    1.9    0.3    0.3

Hide specific rows and the index through chaining:

>>> df.style.format("{:.1f}").hide(subset=(slice(None), ["a", "c"])).hide()
...
                 x                    y
   a      b      c      a      b      c
 0.7    1.0    1.3    1.5   -0.0   -0.2
-0.6    1.2    1.8    1.9    0.3    0.3

Hide a specific level:

>>> df.style.format("{:,.1f}").hide(level=1)
                     x                    y
       a      b      c      a      b      c
x    0.1    0.0    0.4    1.3    0.6   -1.4
     0.7    1.0    1.3    1.5   -0.0   -0.2
     1.4   -0.8    1.6   -0.2   -0.4   -0.3
y    0.4    1.0   -0.2   -0.8   -1.2    1.1
    -0.6    1.2    1.8    1.9    0.3    0.3
     0.8    0.5   -0.3    1.2    2.2   -0.8

Hiding just the index level names:

>>> df.index.names = ["lev0", "lev1"]
>>> df.style.format("{:,.1f}").hide(names=True)
                         x                    y
           a      b      c      a      b      c
x   a    0.1    0.0    0.4    1.3    0.6   -1.4
    b    0.7    1.0    1.3    1.5   -0.0   -0.2
    c    1.4   -0.8    1.6   -0.2   -0.4   -0.3
y   a    0.4    1.0   -0.2   -0.8   -1.2    1.1
    b   -0.6    1.2    1.8    1.9    0.3    0.3
    c    0.8    0.5   -0.3    1.2    2.2   -0.8

Examples all produce equivalently transposed effects with axis="columns".


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4