Skip to content

Commit 9fe2290

Browse files
attack68JulianWgs
authored andcommitted
DOC: update styler user guide for ref to hiding cols and index (pandas-dev#42052)
Co-authored-by: JHM Darbyshire (iMac) <[email protected]>
1 parent ca9b11a commit 9fe2290

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

doc/source/user_guide/style.ipynb

+18-23
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
"\n",
153153
"Before adding styles it is useful to show that the [Styler][styler] can distinguish the *display* value from the *actual* value. To control the display value, the text is printed in each cell, and we can use the [.format()][formatfunc] method to manipulate this according to a [format spec string][format] or a callable that takes a single value and returns a string. It is possible to define this for the whole table or for individual columns. \n",
154154
"\n",
155-
"Additionally, the format function has a **precision** argument to specifically help formatting floats, an **na_rep** argument to display missing data, and an **escape** argument to help displaying safe-HTML. The default formatter is configured to adopt pandas' regular `display.precision` option, controllable using `with pd.option_context('display.precision', 2):`\n",
155+
"Additionally, the format function has a **precision** argument to specifically help formatting floats, as well as **decimal** and **thousands** separators to support other locales, an **na_rep** argument to display missing data, and an **escape** argument to help displaying safe-HTML or safe-LaTeX. The default formatter is configured to adopt pandas' regular `display.precision` option, controllable using `with pd.option_context('display.precision', 2):`\n",
156156
"\n",
157157
"Here is an example of using the multiple options to control the formatting generally and with specific column formatters.\n",
158158
"\n",
@@ -167,9 +167,9 @@
167167
"metadata": {},
168168
"outputs": [],
169169
"source": [
170-
"df.style.format(precision=0, na_rep='MISSING', \n",
170+
"df.style.format(precision=0, na_rep='MISSING', thousands=\" \",\n",
171171
" formatter={('Decision Tree', 'Tumour'): \"{:.2f}\",\n",
172-
" ('Regression', 'Non-Tumour'): lambda x: \"$ {:,.1f}\".format(x*-1e3)\n",
172+
" ('Regression', 'Non-Tumour'): lambda x: \"$ {:,.1f}\".format(x*-1e6)\n",
173173
" })"
174174
]
175175
},
@@ -179,9 +179,11 @@
179179
"source": [
180180
"### Hiding Data\n",
181181
"\n",
182-
"The index can be hidden from rendering by calling [.hide_index()][hideidx], which might be useful if your index is integer based.\n",
182+
"The index and column headers can be completely hidden, as well subselecting rows or columns that one wishes to exclude. Both these options are performed using the same methods.\n",
183183
"\n",
184-
"Columns can be hidden from rendering by calling [.hide_columns()][hidecols] and passing in the name of a column, or a slice of columns.\n",
184+
"The index can be hidden from rendering by calling [.hide_index()][hideidx] without any arguments, which might be useful if your index is integer based. Similarly column headers can be hidden by calling [.hide_columns()][hidecols] without any arguments.\n",
185+
"\n",
186+
"Specific rows or columns can be hidden from rendering by calling the same [.hide_index()][hideidx] or [.hide_columns()][hidecols] methods and passing in a row/column label, a list-like or a slice of row/column labels to for the ``subset`` argument.\n",
185187
"\n",
186188
"Hiding does not change the integer arrangement of CSS classes, e.g. hiding the first two columns of a DataFrame means the column class indexing will start at `col2`, since `col0` and `col1` are simply ignored.\n",
187189
"\n",
@@ -1419,24 +1421,6 @@
14191421
"])"
14201422
]
14211423
},
1422-
{
1423-
"cell_type": "markdown",
1424-
"metadata": {},
1425-
"source": [
1426-
"### Hiding Headers\n",
1427-
"\n",
1428-
"We don't yet have any API to hide headers so a quick fix is:"
1429-
]
1430-
},
1431-
{
1432-
"cell_type": "code",
1433-
"execution_count": null,
1434-
"metadata": {},
1435-
"outputs": [],
1436-
"source": [
1437-
"df3.style.set_table_styles([{'selector': 'thead tr', 'props': 'display: none;'}]) # or 'thead th'"
1438-
]
1439-
},
14401424
{
14411425
"cell_type": "markdown",
14421426
"metadata": {},
@@ -1524,6 +1508,17 @@
15241508
"![Excel spreadsheet with styled DataFrame](../_static/style-excel.png)\n"
15251509
]
15261510
},
1511+
{
1512+
"cell_type": "markdown",
1513+
"metadata": {},
1514+
"source": [
1515+
"## Export to LaTeX\n",
1516+
"\n",
1517+
"There is support (*since version 1.3.0*) to export `Styler` to LaTeX. The documentation for the [.to_latex][latex] method gives further detail and numerous examples.\n",
1518+
"\n",
1519+
"[latex]: ../reference/api/pandas.io.formats.style.Styler.to_latex.rst"
1520+
]
1521+
},
15271522
{
15281523
"cell_type": "markdown",
15291524
"metadata": {},

0 commit comments

Comments
 (0)