8000 df.style des not render pivot tables in the same fashion as to_html · Issue #13140 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content
df.style des not render pivot tables in the same fashion as to_html #13140
@gbronner

Description

@gbronner

Please see
http://stackoverflow.com/questions/37166730/how-do-i-preserve-hierarchical-tables-with-pandas-pivot-table-and-dataframe-styl

Code Sample, a copy-pastable example if possible

import pandas as pd
import numpy as np

np.random.seed(0)
a = np.random.randint(1, 4, 10)
b = np.random.randint(1, 4, 10)
c = np.random.randint(5, 9, 10)

df = pd.DataFrame(dict(A=a,B=b,C=c,Val=np.random.randint(1,10,10)))

tbl=pd.pivot_table(df,index=['A','B','C'], aggfunc=sum)
print tbl.to_html()
print tbl.style.render()

Expected Output

Expect that both tables will produce nearly indentical hierarchically structured tables, and in particular, the second table will not have every index value repeated.
`

Val
A B C
1 1 5 1
2 5 4
6 4
8 9
2 3 5 2
6 3
8 9
3 1 8 4
2 7 4
    <style  type="text/css" >


    </style>

    <table id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" None>


    <thead>

        <tr>

            <th class="blank">

            <th class="blank">

            <th class="blank">

            <th class="col_heading level0 col0">Val

        </tr>

        <tr>

            <th class="col_heading level2 col0">A

            <th class="col_heading level2 col1">B

            <th class="col_heading level2 col2">C

            <th class="blank">

        </tr>

    </thead>
    <tbody>

        <tr>

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level2 row0">
                1

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level2 row0">
                1

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level2 row0">
                5

            <td id="T_ae86631e_1789_11e6_aa5c_3417ebaea714row0_col0" class="data row0 col0">
                1

        </tr>

        <tr>

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row1">
                1

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row1">
                2

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row1">
                5

            <td id="T_ae86631e_1789_11e6_aa5c_3417ebaea714row1_col0" class="data row1 col0">
                4

        </tr>

        <tr>

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row2">
                1

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row2">
                2

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row2">
                6

            <td id="T_ae86631e_1789_11e6_aa5c_3417ebaea714row2_col0" class="data row2 col0">
                4

        </tr>

        <tr>

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row3">
                1

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row3">
                2

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row3">
                8

            <td id="T_ae86631e_1789_11e6_aa5c_3417ebaea714row3_col0" class="data row3 col0">
                9

        </tr>

        <tr>

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row4">
                2

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row4">
                3

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row4">
                5

            <td id="T_ae86631e_1789_11e6_aa5c_3417ebaea714row4_col0" class="data row4 col0">
                2

        </tr>

        <tr>

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row5">
                2

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row5">
                3

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row5">
                6

            <td id="T_ae86631e_1789_11e6_aa5c_3417ebaea714row5_col0" class="data row5 col0">
                3

        </tr>

        <tr>

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row6">
                2

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row6">
                3

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row6">
                8

            <td id="T_ae86631e_1789_11e6_aa5c_3417ebaea714row6_col0" class="data row6 col0">
                9

        </tr>

        <tr>

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row7">
                3

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row7">
                1

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row7">
                8

            <td id="T_ae86631e_1789_11e6_aa5c_3417ebaea714row7_col0" class="data row7 col0">
                4

        </tr>

        <tr>

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row8">
                3

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row8">
                2

            <th id="T_ae86631e_1789_11e6_aa5c_3417ebaea714" class="row_heading level0 row8">
                7

            <td id="T_ae86631e_1789_11e6_aa5c_3417ebaea714row8_col0" class="data row8 col0">
                4

        </tr>

    </tbody>
    </table>`

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.11.final.0
python-bits: 32
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.1
nose: None
pip: 8.1.1
setuptools: 20.2.2
Cython: None
numpy: 1.11.0
scipy: None
statsmodels: None
xarray: None
IPython: 4.1.2
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: 1.0.0
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: 0.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO HTMLread_html, to_html, Styler.apply, Styler.applymapMultiIndexOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0