Skip to content

Commit 506f3d2

Browse files
committed
Added documentation on the new df.style.bar options for align and Colors in the documentation.
1 parent e0563d5 commit 506f3d2

File tree

1 file changed

+98
-12
lines changed

1 file changed

+98
-12
lines changed

doc/source/html-styling.ipynb

+98-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"cells": [
33
{
4-
"cell_type": "markdown",
5-
"metadata": {},
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
610
"source": [
711
"*New in version 0.17.1*\n",
812
"\n",
@@ -31,6 +35,24 @@
3135
"- [Extensibility](#Extensibility)"
3236
]
3337
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": null,
41+
"metadata": {
42+
"collapsed": true
43+
},
44+
"outputs": [],
45+
"source": []
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": null,
50+
"metadata": {
51+
"collapsed": true
52+
},
53+
"outputs": [],
54+
"source": []
55+
},
3456
{
3557
"cell_type": "markdown",
3658
"metadata": {},
@@ -518,7 +540,7 @@
518540
"cell_type": "markdown",
519541
"metadata": {},
520542
"source": [
521-
"You can include \"bar charts\" in your DataFrame."
543+
"There's also `.highlight_min` and `.highlight_max`."
522544
]
523545
},
524546
{
@@ -529,14 +551,25 @@
529551
},
530552
"outputs": [],
531553
"source": [
532-
"df.style.bar(subset=['A', 'B'], color='#d65f5f')"
554+
"df.style.highlight_max(axis=0)"
555+
]
556+
},
557+
{
558+
"cell_type": "code",
559+
"execution_count": null,
560+
"metadata": {
561+
"collapsed": false
562+
},
563+
"outputs": [],
564+
"source": [
565+
"df.style.highlight_min(axis=0)"
533566
]
534567
},
535568
{
536569
"cell_type": "markdown",
537570
"metadata": {},
538571
"source": [
539-
"There's also `.highlight_min` and `.highlight_max`."
572+
"Use `Styler.set_properties` when the style doesn't actually depend on the values."
540573
]
541574
},
542575
{
@@ -547,7 +580,23 @@
547580
},
548581
"outputs": [],
549582
"source": [
550-
"df.style.highlight_max(axis=0)"
583+
"df.style.set_properties(**{'background-color': 'black',\n",
584+
" 'color': 'lawngreen',\n",
585+
" 'border-color': 'white'})"
586+
]
587+
},
588+
{
589+
"cell_type": "markdown",
590+
"metadata": {},
591+
"source": [
592+
"### Bar charts"
593+
]
594+
},
595+
{
596+
"cell_type": "markdown",
597+
"metadata": {},
598+
"source": [
599+
"You can include \"bar charts\" in your DataFrame."
551600
]
552601
},
553602
{
@@ -558,14 +607,16 @@
558607
},
559608
"outputs": [],
560609
"source": [
561-
"df.style.highlight_min(axis=0)"
610+
"df.style.bar(subset=['A', 'B'], color='#d65f5f')"
562611
]
563612
},
564613
{
565614
"cell_type": "markdown",
566615
"metadata": {},
567616
"source": [
568-
"Use `Styler.set_properties` when the style doesn't actually depend on the values."
617+
"New in version 0.19.2 is the ability to customize further the bar chart: You can now have the `df.style.bar` be centered on zero or midpoint value (in addition to the already existing way of having the min value at the left side of the cell), and you can pass a list of `[color_negative, color_positive]`.\n",
618+
"\n",
619+
"The following example shows the behavior of the new align options:"
569620
]
570621
},
571622
{
@@ -576,9 +627,44 @@
576627
},
577628
"outputs": [],
578629
"source": [
579-
"df.style.set_properties(**{'background-color': 'black',\n",
580-
" 'color': 'lawngreen',\n",
581-
" 'border-color': 'white'})"
630+
"import pandas as pd\n",
631+
"from IPython.display import HTML\n",
632+
"\n",
633+
"# Test series\n",
634+
"test1 = pd.Series([-100,-60,-30,-20], name='All Negative')\n",
635+
"test2 = pd.Series([10,20,50,100], name='All Positive')\n",
636+
"test3 = pd.Series([-10,-5,0,90], name='Both Pos and Neg')\n",
637+
"\n",
638+
"head = \"\"\"\n",
639+
"<table>\n",
640+
" <thead>\n",
641+
" <th>Align</th>\n",
642+
" <th>All Negative</th>\n",
643+
" <th>All Positive</th>\n",
644+
" <th>Both Neg and Pos</th>\n",
645+
" </thead>\n",
646+
" </tbody>\n",
647+
"\n",
648+
"\"\"\"\n",
649+
"\n",
650+
"aligns = ['left','zero','mid']\n",
651+
"for align in aligns:\n",
652+
" row = \"<tr><th>{}</th>\".format(align)\n",
653+
" for serie in [test1,test2,test3]:\n",
654+
" s = serie.copy()\n",
655+
" s.name=''\n",
656+
" row += \"<td>{}</td>\".format(s.to_frame().style.bar(align=align, \n",
657+
" color=['#d65f5f', '#5fba7d'], \n",
658+
" width=100).render()) #testn['width']\n",
659+
" row += '</tr>'\n",
660+
" head += row\n",
661+
" \n",
662+
"head+= \"\"\"\n",
663+
"</tbody>\n",
664+
"</table>\"\"\"\n",
665+
" \n",
666+
"\n",
667+
"HTML(head)"
582668
]
583669
},
584670
{
@@ -961,7 +1047,7 @@
9611047
"name": "python",
9621048
"nbconvert_exporter": "python",
9631049
"pygments_lexer": "ipython3",
964-
"version": "3.5.1"
1050+
"version": "3.5.2"
9651051
}
9661052
},
9671053
"nbformat": 4,

0 commit comments

Comments
 (0)