Skip to content
Permalink
Browse files

Doc tweaks

  • Loading branch information...
jnothman committed Apr 9, 2017
1 parent 2c3d015 commit c4f59c68ee1fb9aa9993a79a8bc95f7974d9000a
Showing with 38 additions and 99 deletions.
  1. BIN doc/source/_static/style-excel.png
  2. +33 −93 doc/source/style.ipynb
  3. +5 −6 doc/source/whatsnew/v0.20.0.txt
Binary file not shown.
@@ -49,7 +49,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"nbsphinx": "hidden"
},
"outputs": [],
@@ -62,9 +61,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
@@ -87,9 +84,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style"
@@ -107,9 +102,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.highlight_null().render().split('\\n')[:10]"
@@ -158,9 +151,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"s = df.style.applymap(color_negative_red)\n",
@@ -204,9 +195,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.apply(highlight_max)"
@@ -230,9 +219,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.\\\n",
@@ -284,9 +271,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.apply(highlight_max, color='darkorange', axis=None)"
@@ -334,9 +319,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.apply(highlight_max, subset=['B', 'C', 'D'])"
@@ -352,9 +335,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.applymap(color_negative_red,\n",
@@ -387,9 +368,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.format(\"{:.2%}\")"
@@ -405,9 +384,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.format({'B': \"{:0<4.0f}\", 'D': '{:+.2f}'})"
@@ -423,9 +400,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.format({\"B\": lambda x: \"±{:.2f}\".format(abs(x))})"
@@ -448,9 +423,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.highlight_null(null_color='red')"
@@ -466,9 +439,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"import seaborn as sns\n",
@@ -489,9 +460,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Uses the full color range\n",
@@ -501,9 +470,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Compreess the color range\n",
@@ -523,9 +490,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.bar(subset=['A', 'B'], color='#d65f5f')"
@@ -541,9 +506,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.highlight_max(axis=0)"
@@ -552,9 +515,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.highlight_min(axis=0)"
@@ -570,9 +531,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.set_properties(**{'background-color': 'black',\n",
@@ -597,9 +556,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df2 = -df\n",
@@ -610,9 +567,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"style2 = df2.style\n",
@@ -665,9 +620,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"with pd.option_context('display.precision', 2):\n",
@@ -687,9 +640,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style\\\n",
@@ -722,9 +673,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"df.style.set_caption('Colormaps, with a caption.')\\\n",
@@ -750,9 +699,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import HTML\n",
@@ -848,9 +795,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"from IPython.html import widgets\n",
@@ -865,9 +810,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def magnify():\n",
@@ -886,9 +829,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"np.random.seed(25)\n",
@@ -908,7 +849,7 @@
"source": [
"# Export to Excel\n",
"\n",
"*New in version 0.19.0*\n",
"*New in version 0.20.0*\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",
"\n",
@@ -937,15 +878,15 @@
"df.style.\\\n",
" applymap(color_negative_red).\\\n",
" apply(highlight_max).\\\n",
" to_excel('_static/styled.xlsx', engine='openpyxl')"
" to_excel('styled.xlsx', engine='openpyxl')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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\">"
]
},
{
@@ -1005,8 +946,7 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
@@ -325,17 +325,16 @@ For example, after running the following, ``styled.xlsx`` renders as below:

.. ipython:: python

import pandas as pd
import numpy as np

np.random.seed(24)
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)
df.iloc[0, 2] = np.nan
df.style.\
applymap(color_negative_red).\
apply(highlight_max).\
applymap(lambda val: 'color: %s' % 'red' if val < 0 else 'black').\
apply(lambda s: ['background-color: yellow' if v else ''
for v in s == s.max()]).\
to_excel('styled.xlsx', engine='openpyxl')

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

0 comments on commit c4f59c6

Please sign in to comment.
You can’t perform that action at this time.