Added documentation on the new df.style.bar options for align and Col… · jreback/pandas@506f3d2 (original) (raw)

1

1

`{

`

2

2

`"cells": [

`

3

3

` {

`

4

``

`-

"cell_type": "markdown",

`

5

``

`-

"metadata": {},

`

``

4

`+

"cell_type": "code",

`

``

5

`+

"execution_count": null,

`

``

6

`+

"metadata": {

`

``

7

`+

"collapsed": true

`

``

8

`+

},

`

``

9

`+

"outputs": [],

`

6

10

`"source": [

`

7

11

`"New in version 0.17.1\n",

`

8

12

`"\n",

`

31

35

`"- Extensibility"

`

32

36

` ]

`

33

37

` },

`

``

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

`+

},

`

34

56

` {

`

35

57

`"cell_type": "markdown",

`

36

58

`"metadata": {},

`

518

540

`"cell_type": "markdown",

`

519

541

`"metadata": {},

`

520

542

`"source": [

`

521

``

`-

"You can include "bar charts" in your DataFrame."

`

``

543

`` +

"There's also .highlight_min and .highlight_max."

``

522

544

` ]

`

523

545

` },

`

524

546

` {

`

`@@ -529,14 +551,25 @@

`

529

551

` },

`

530

552

`"outputs": [],

`

531

553

`"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)"

`

533

566

` ]

`

534

567

` },

`

535

568

` {

`

536

569

`"cell_type": "markdown",

`

537

570

`"metadata": {},

`

538

571

`"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."

``

540

573

` ]

`

541

574

` },

`

542

575

` {

`

`@@ -547,7 +580,23 @@

`

547

580

` },

`

548

581

`"outputs": [],

`

549

582

`"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."

`

551

600

` ]

`

552

601

` },

`

553

602

` {

`

`@@ -558,14 +607,16 @@

`

558

607

` },

`

559

608

`"outputs": [],

`

560

609

`"source": [

`

561

``

`-

"df.style.highlight_min(axis=0)"

`

``

610

`+

"df.style.bar(subset=['A', 'B'], color='#d65f5f')"

`

562

611

` ]

`

563

612

` },

`

564

613

` {

`

565

614

`"cell_type": "markdown",

`

566

615

`"metadata": {},

`

567

616

`"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:"

`

569

620

` ]

`

570

621

` },

`

571

622

` {

`

`@@ -576,9 +627,44 @@

`

576

627

` },

`

577

628

`"outputs": [],

`

578

629

`"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

`+

"

\n",

`

``

640

`+

"

\n",

`

``

641

`+

"

\n",

`

``

642

`+

"

\n",

`

``

643

`+

"

\n",

`

``

644

`+

"

\n",

`

``

645

`+

" \n",

`

``

646

`+

" \n",

`

``

647

`+

"\n",

`

``

648

`+

""""\n",

`

``

649

`+

"\n",

`

``

650

`+

"aligns = ['left','zero','mid']\n",

`

``

651

`+

"for align in aligns:\n",

`

``

652

`+

" row = "

".format(align)\n",

`

``

653

`+

" for serie in [test1,test2,test3]:\n",

`

``

654

`+

" s = serie.copy()\n",

`

``

655

`+

" s.name=''\n",

`

``

656

`+

" row += "

".format(s.to_frame().style.bar(align=align, \n",

`

``

657

`+

" color=['#d65f5f', '#5fba7d'], \n",

`

``

658

`+

" width=100).render()) #testn['width']\n",

`

``

659

`+

" row += ''\n",

`

``

660

`+

" head += row\n",

`

``

661

`+

" \n",

`

``

662

`+

"head+= """\n",

`

``

663

`+

"\n",

`

``

664

`+

"

Align All Negative All Positive Both Neg and Pos
{}
{}
"""\n",

`

``

665

`+

" \n",

`

``

666

`+

"\n",

`

``

667

`+

"HTML(head)"

`

582

668

` ]

`

583

669

` },

`

584

670

` {

`

961

1047

`"name": "python",

`

962

1048

`"nbconvert_exporter": "python",

`

963

1049

`"pygments_lexer": "ipython3",

`

964

``

`-

"version": "3.5.1"

`

``

1050

`+

"version": "3.5.2"

`

965

1051

` }

`

966

1052

` },

`

967

1053

`"nbformat": 4,

`