|
152 | 152 | "\n",
|
153 | 153 | "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",
|
154 | 154 | "\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", |
156 | 156 | "\n",
|
157 | 157 | "Here is an example of using the multiple options to control the formatting generally and with specific column formatters.\n",
|
158 | 158 | "\n",
|
|
167 | 167 | "metadata": {},
|
168 | 168 | "outputs": [],
|
169 | 169 | "source": [
|
170 |
| - "df.style.format(precision=0, na_rep='MISSING', \n", |
| 170 | + "df.style.format(precision=0, na_rep='MISSING', thousands=\" \",\n", |
171 | 171 | " 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", |
173 | 173 | " })"
|
174 | 174 | ]
|
175 | 175 | },
|
|
179 | 179 | "source": [
|
180 | 180 | "### Hiding Data\n",
|
181 | 181 | "\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", |
183 | 183 | "\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", |
185 | 187 | "\n",
|
186 | 188 | "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",
|
187 | 189 | "\n",
|
|
1419 | 1421 | "])"
|
1420 | 1422 | ]
|
1421 | 1423 | },
|
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 |
| - }, |
1440 | 1424 | {
|
1441 | 1425 | "cell_type": "markdown",
|
1442 | 1426 | "metadata": {},
|
|
1524 | 1508 | "\n"
|
1525 | 1509 | ]
|
1526 | 1510 | },
|
| 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 | + }, |
1527 | 1522 | {
|
1528 | 1523 | "cell_type": "markdown",
|
1529 | 1524 | "metadata": {},
|
|
0 commit comments