Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

df.style des not render pivot tables in the same fashion as to_html #13140

Closed
gbronner opened this issue May 11, 2016 · 2 comments
Closed

df.style des not render pivot tables in the same fashion as to_html #13140

gbronner opened this issue May 11, 2016 · 2 comments
Labels
IO HTML read_html, to_html, Styler.apply, Styler.applymap MultiIndex Output-Formatting __repr__ of pandas objects, to_string

Comments

@gbronner
Copy link

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

@jreback
Copy link
Contributor

jreback commented May 11, 2016

this looks like just manifesting for unfinished in #11610, in paticular MultiIndex is not well supported yet.

@gbronner pull-requests are welcome.

@TomAugspurger i'll leave you to mark / close if its a dupe or you want to keep open.

@jreback jreback modified the milestone: multi May 11, 2016
@jreback jreback added Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap MultiIndex labels May 11, 2016
@TomAugspurger
Copy link
Contributor

This the same as #11655

@gbronner If you're interested in trying to fix this, I'd be happy help review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO HTML read_html, to_html, Styler.apply, Styler.applymap MultiIndex Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

No branches or pull requests

3 participants