Skip to content

Commit

Permalink
Doc tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jnothman committed Apr 9, 2017
1 parent 2c3d015 commit c4f59c6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 99 deletions.
Binary file modified doc/source/_static/style-excel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 33 additions & 93 deletions doc/source/style.ipynb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": true,
"nbsphinx": "hidden" "nbsphinx": "hidden"
}, },
"outputs": [], "outputs": [],
Expand All @@ -62,9 +61,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import pandas as pd\n", "import pandas as pd\n",
Expand All @@ -87,9 +84,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style" "df.style"
Expand All @@ -107,9 +102,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.highlight_null().render().split('\\n')[:10]" "df.style.highlight_null().render().split('\\n')[:10]"
Expand Down Expand Up @@ -158,9 +151,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"s = df.style.applymap(color_negative_red)\n", "s = df.style.applymap(color_negative_red)\n",
Expand Down Expand Up @@ -204,9 +195,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.apply(highlight_max)" "df.style.apply(highlight_max)"
Expand All @@ -230,9 +219,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.\\\n", "df.style.\\\n",
Expand Down Expand Up @@ -284,9 +271,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.apply(highlight_max, color='darkorange', axis=None)" "df.style.apply(highlight_max, color='darkorange', axis=None)"
Expand Down Expand Up @@ -334,9 +319,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.apply(highlight_max, subset=['B', 'C', 'D'])" "df.style.apply(highlight_max, subset=['B', 'C', 'D'])"
Expand All @@ -352,9 +335,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.applymap(color_negative_red,\n", "df.style.applymap(color_negative_red,\n",
Expand Down Expand Up @@ -387,9 +368,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.format(\"{:.2%}\")" "df.style.format(\"{:.2%}\")"
Expand All @@ -405,9 +384,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.format({'B': \"{:0<4.0f}\", 'D': '{:+.2f}'})" "df.style.format({'B': \"{:0<4.0f}\", 'D': '{:+.2f}'})"
Expand All @@ -423,9 +400,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.format({\"B\": lambda x: \"±{:.2f}\".format(abs(x))})" "df.style.format({\"B\": lambda x: \"±{:.2f}\".format(abs(x))})"
Expand All @@ -448,9 +423,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.highlight_null(null_color='red')" "df.style.highlight_null(null_color='red')"
Expand All @@ -466,9 +439,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"import seaborn as sns\n", "import seaborn as sns\n",
Expand All @@ -489,9 +460,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Uses the full color range\n", "# Uses the full color range\n",
Expand All @@ -501,9 +470,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Compreess the color range\n", "# Compreess the color range\n",
Expand All @@ -523,9 +490,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.bar(subset=['A', 'B'], color='#d65f5f')" "df.style.bar(subset=['A', 'B'], color='#d65f5f')"
Expand All @@ -541,9 +506,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.highlight_max(axis=0)" "df.style.highlight_max(axis=0)"
Expand All @@ -552,9 +515,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.highlight_min(axis=0)" "df.style.highlight_min(axis=0)"
Expand All @@ -570,9 +531,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.set_properties(**{'background-color': 'black',\n", "df.style.set_properties(**{'background-color': 'black',\n",
Expand All @@ -597,9 +556,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df2 = -df\n", "df2 = -df\n",
Expand All @@ -610,9 +567,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"style2 = df2.style\n", "style2 = df2.style\n",
Expand Down Expand Up @@ -665,9 +620,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"with pd.option_context('display.precision', 2):\n", "with pd.option_context('display.precision', 2):\n",
Expand All @@ -687,9 +640,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style\\\n", "df.style\\\n",
Expand Down Expand Up @@ -722,9 +673,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"df.style.set_caption('Colormaps, with a caption.')\\\n", "df.style.set_caption('Colormaps, with a caption.')\\\n",
Expand All @@ -750,9 +699,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from IPython.display import HTML\n", "from IPython.display import HTML\n",
Expand Down Expand Up @@ -848,9 +795,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from IPython.html import widgets\n", "from IPython.html import widgets\n",
Expand All @@ -865,9 +810,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"def magnify():\n", "def magnify():\n",
Expand All @@ -886,9 +829,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"np.random.seed(25)\n", "np.random.seed(25)\n",
Expand All @@ -908,7 +849,7 @@
"source": [ "source": [
"# Export to Excel\n", "# Export to Excel\n",
"\n", "\n",
"*New in version 0.19.0*\n", "*New in version 0.20.0*\n",
"\n", "\n",
"<p 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](https://github.com/pandas-dev/pandas/issues).*<p style=\"color: red\">\n", "<p 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](https://github.com/pandas-dev/pandas/issues).*<p style=\"color: red\">\n",
"\n", "\n",
Expand Down Expand Up @@ -937,15 +878,15 @@
"df.style.\\\n", "df.style.\\\n",
" applymap(color_negative_red).\\\n", " applymap(color_negative_red).\\\n",
" apply(highlight_max).\\\n", " apply(highlight_max).\\\n",
" to_excel('_static/styled.xlsx', engine='openpyxl')" " to_excel('styled.xlsx', engine='openpyxl')"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"A screenshot of the output:\n", "A screenshot of the output:\n",
"<a href=\"_static/styled.xlsx\"><img alt=\"Excel spreadsheet with styled DataFrame\" src=\"_static/style-excel.png\"></a>" "<img alt=\"Excel spreadsheet with styled DataFrame\" src=\"_static/style-excel.png\">"
] ]
}, },
{ {
Expand Down Expand Up @@ -1005,8 +946,7 @@
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3"
"version": "3.6.1"
} }
}, },
"nbformat": 4, "nbformat": 4,
Expand Down
11 changes: 5 additions & 6 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -325,17 +325,16 @@ For example, after running the following, ``styled.xlsx`` renders as below:


.. ipython:: python .. ipython:: python


import pandas as pd
import numpy as np

np.random.seed(24) np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)}) df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))], df = pd.concat([df, pd.DataFrame(np.random.RandomState(24).randn(10, 4),
columns=list('BCDE'))],
axis=1) axis=1)
df.iloc[0, 2] = np.nan df.iloc[0, 2] = np.nan
df.style.\ df.style.\
applymap(color_negative_red).\ applymap(lambda val: 'color: %s' % 'red' if val < 0 else 'black').\
apply(highlight_max).\ apply(lambda s: ['background-color: yellow' if v else ''
for v in s == s.max()]).\
to_excel('styled.xlsx', engine='openpyxl') to_excel('styled.xlsx', engine='openpyxl')


.. image:: _static/style-excel.png .. image:: _static/style-excel.png
Expand Down

0 comments on commit c4f59c6

Please sign in to comment.