|
4 | 4 | "cell_type": "markdown",
|
5 | 5 | "metadata": {},
|
6 | 6 | "source": [
|
7 |
| - "# HTML Styling\n", |
| 7 | + "# Styling\n", |
8 | 8 | "\n",
|
9 | 9 | "*New in version 0.17.1*\n",
|
10 | 10 | "\n",
|
11 |
| - "<p style=\"color: red\">*Provisional: This is a new feature and still under development. We'll be adding features and possibly making breaking changes in future releases. We'd love to hear your feedback.*<p style=\"color: red\">\n", |
| 11 | + "<span style=\"color: red\">*Provisional: This is a new feature and still under development. We'll be adding features and possibly making breaking changes in future releases. We'd love to hear your feedback.*</span>\n", |
12 | 12 | "\n",
|
13 | 13 | "This document is written as a Jupyter Notebook, and can be viewed or downloaded [here](http://nbviewer.ipython.org/github/pandas-dev/pandas/blob/master/doc/source/html-styling.ipynb).\n",
|
14 | 14 | "\n",
|
|
49 | 49 | "cell_type": "code",
|
50 | 50 | "execution_count": null,
|
51 | 51 | "metadata": {
|
52 |
| - "collapsed": true, |
53 | 52 | "nbsphinx": "hidden"
|
54 | 53 | },
|
55 | 54 | "outputs": [],
|
|
62 | 61 | {
|
63 | 62 | "cell_type": "code",
|
64 | 63 | "execution_count": null,
|
65 |
| - "metadata": { |
66 |
| - "collapsed": true |
67 |
| - }, |
| 64 | + "metadata": {}, |
68 | 65 | "outputs": [],
|
69 | 66 | "source": [
|
70 | 67 | "import pandas as pd\n",
|
|
130 | 127 | {
|
131 | 128 | "cell_type": "code",
|
132 | 129 | "execution_count": null,
|
133 |
| - "metadata": { |
134 |
| - "collapsed": true |
135 |
| - }, |
| 130 | + "metadata": {}, |
136 | 131 | "outputs": [],
|
137 | 132 | "source": [
|
138 | 133 | "def color_negative_red(val):\n",
|
|
186 | 181 | {
|
187 | 182 | "cell_type": "code",
|
188 | 183 | "execution_count": null,
|
189 |
| - "metadata": { |
190 |
| - "collapsed": true |
191 |
| - }, |
| 184 | + "metadata": {}, |
192 | 185 | "outputs": [],
|
193 | 186 | "source": [
|
194 | 187 | "def highlight_max(s):\n",
|
|
240 | 233 | "source": [
|
241 | 234 | "Above we used `Styler.apply` to pass in each column one at a time.\n",
|
242 | 235 | "\n",
|
243 |
| - "<p style=\"background-color: #DEDEBE\">*Debugging Tip*: If you're having trouble writing your style function, try just passing it into <code style=\"background-color: #DEDEBE\">DataFrame.apply</code>. Internally, <code style=\"background-color: #DEDEBE\">Styler.apply</code> uses <code style=\"background-color: #DEDEBE\">DataFrame.apply</code> so the result should be the same.</p>\n", |
| 236 | + "<span style=\"background-color: #DEDEBE\">*Debugging Tip*: If you're having trouble writing your style function, try just passing it into <code style=\"background-color: #DEDEBE\">DataFrame.apply</code>. Internally, <code style=\"background-color: #DEDEBE\">Styler.apply</code> uses <code style=\"background-color: #DEDEBE\">DataFrame.apply</code> so the result should be the same.</span>\n", |
244 | 237 | "\n",
|
245 | 238 | "What if you wanted to highlight just the maximum value in the entire table?\n",
|
246 | 239 | "Use `.apply(function, axis=None)` to indicate that your function wants the entire table, not one column or row at a time. Let's try that next.\n",
|
|
251 | 244 | {
|
252 | 245 | "cell_type": "code",
|
253 | 246 | "execution_count": null,
|
254 |
| - "metadata": { |
255 |
| - "collapsed": true |
256 |
| - }, |
| 247 | + "metadata": {}, |
257 | 248 | "outputs": [],
|
258 | 249 | "source": [
|
259 | 250 | "def highlight_max(data, color='yellow'):\n",
|
|
819 | 810 | {
|
820 | 811 | "cell_type": "code",
|
821 | 812 | "execution_count": null,
|
822 |
| - "metadata": { |
823 |
| - "collapsed": true |
824 |
| - }, |
| 813 | + "metadata": {}, |
825 | 814 | "outputs": [],
|
826 | 815 | "source": [
|
827 | 816 | "def magnify():\n",
|
|
854 | 843 | " .set_table_styles(magnify())"
|
855 | 844 | ]
|
856 | 845 | },
|
| 846 | + { |
| 847 | + "cell_type": "markdown", |
| 848 | + "metadata": {}, |
| 849 | + "source": [ |
| 850 | + "## Export to Excel\n", |
| 851 | + "\n", |
| 852 | + "*New in version 0.20.0*\n", |
| 853 | + "\n", |
| 854 | + "<span style=\"color: red\">*Experimental: This is a new feature and still under development. We'll be adding features and possibly making breaking changes in future releases. We'd love to hear your feedback.*</span>\n", |
| 855 | + "\n", |
| 856 | + "Some support is available for exporting styled `DataFrames` to Excel worksheets using the `OpenPyXL` engine. CSS2.2 properties handled include:\n", |
| 857 | + "\n", |
| 858 | + "- `background-color`\n", |
| 859 | + "- `border-style`, `border-width`, `border-color` and their {`top`, `right`, `bottom`, `left` variants}\n", |
| 860 | + "- `color`\n", |
| 861 | + "- `font-family`\n", |
| 862 | + "- `font-style`\n", |
| 863 | + "- `font-weight`\n", |
| 864 | + "- `text-align`\n", |
| 865 | + "- `text-decoration`\n", |
| 866 | + "- `vertical-align`\n", |
| 867 | + "- `white-space: nowrap`\n", |
| 868 | + "\n", |
| 869 | + "Only CSS2 named colors and hex colors of the form `#rgb` or `#rrggbb` are currently supported." |
| 870 | + ] |
| 871 | + }, |
| 872 | + { |
| 873 | + "cell_type": "code", |
| 874 | + "execution_count": null, |
| 875 | + "metadata": {}, |
| 876 | + "outputs": [], |
| 877 | + "source": [ |
| 878 | + "df.style.\\\n", |
| 879 | + " applymap(color_negative_red).\\\n", |
| 880 | + " apply(highlight_max).\\\n", |
| 881 | + " to_excel('styled.xlsx', engine='openpyxl')" |
| 882 | + ] |
| 883 | + }, |
| 884 | + { |
| 885 | + "cell_type": "markdown", |
| 886 | + "metadata": {}, |
| 887 | + "source": [ |
| 888 | + "A screenshot of the output:\n", |
| 889 | + "\n", |
| 890 | + "\n" |
| 891 | + ] |
| 892 | + }, |
857 | 893 | {
|
858 | 894 | "cell_type": "markdown",
|
859 | 895 | "metadata": {},
|
|
1039 | 1075 | "mimetype": "text/x-python",
|
1040 | 1076 | "name": "python",
|
1041 | 1077 | "nbconvert_exporter": "python",
|
1042 |
| - "pygments_lexer": "ipython3", |
1043 |
| - "version": "3.6.1" |
| 1078 | + "pygments_lexer": "ipython3" |
1044 | 1079 | }
|
1045 | 1080 | },
|
1046 | 1081 | "nbformat": 4,
|
|
0 commit comments