Pandas: Styler render creates extra indent which when exported to markdown becomes a code block

Created on 11 Mar 2017  路  2Comments  路  Source: pandas-dev/pandas

Code Sample, a copy-pastable example if possible

# Your code here
In [12]: df
Out[12]:
   A       B       C
0  1  0.5021 -1.8989
1  0 -0.0123  0.4893
2  0 -1.0470 -0.9169

In [13]: print(df.style.set_caption('example').render())

        <style  type="text/css" >


        </style>

        <table id="T_abffa708_05f4_11e7_920b_acbc329287af" None>

            <caption>example</caption>


        <thead>

            <tr>


                <th class="blank level0" >




                <th class="col_heading level0 col0" colspan=1>
                  A

Problem description

Although the above output renders fine in an ipython notebook, when that notebook is then exported to markdown, the indent is interpreted as a code block so the output HTML renders as a code block

Expected Output

Same thing, just no indent.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 16.0.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.19.2
nose: None
pip: 8.1.2
setuptools: 34.1.1
Cython: None
numpy: 1.12.0
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.2.1
sphinx: None
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.9999999
httplib2: None
apiclient: None
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.5
boto: None
pandas_datareader: None

IO HTML

Most helpful comment

@danfrankj I have a branch here that fixes this. I'll make sure to have it in before our next release. The generated HTML should be much nicer to view as well (less whitespace and careless indenting).

All 2 comments

@danfrankj I have a branch here that fixes this. I'll make sure to have it in before our next release. The generated HTML should be much nicer to view as well (less whitespace and careless indenting).

Closed by #15954

In [3]: df
Out[3]:
   A       B       C
0  1  0.5021 -1.8989
1  0 -0.0123  0.4893
2  0 -1.0470 -0.9169

In [4]: print(df.style.set_caption('example').render())
<style  type="text/css" >
</style>
<table id="T_dd1e2328_21f7_11e7_995e_186590cd1c87" ><caption>example</caption>
<thead>    <tr>
        <th class="blank level0" ></th>
        <th class="col_heading level0 col0" >A</th>
        <th class="col_heading level0 col1" >B</th>
        <th class="col_heading level0 col2" >C</th>
    </tr></thead>
<tbody>    <tr>
        <th id="T_dd1e2328_21f7_11e7_995e_186590cd1c87" class="row_heading level0 row0" >0</th>
        <td id="T_dd1e2328_21f7_11e7_995e_186590cd1c87row0_col0" class="data row0 col0" >1</td>
        <td id="T_dd1e2328_21f7_11e7_995e_186590cd1c87row0_col1" class="data row0 col1" >0.5021</td>
        <td id="T_dd1e2328_21f7_11e7_995e_186590cd1c87row0_col2" class="data row0 col2" >-1.8989</td>
    </tr>    <tr>
        <th id="T_dd1e2328_21f7_11e7_995e_186590cd1c87" class="row_heading level0 row1" >1</th>
        <td id="T_dd1e2328_21f7_11e7_995e_186590cd1c87row1_col0" class="data row1 col0" >0</td>
        <td id="T_dd1e2328_21f7_11e7_995e_186590cd1c87row1_col1" class="data row1 col1" >-0.0123</td>
        <td id="T_dd1e2328_21f7_11e7_995e_186590cd1c87row1_col2" class="data row1 col2" >0.4893</td>
    </tr>    <tr>
        <th id="T_dd1e2328_21f7_11e7_995e_186590cd1c87" class="row_heading level0 row2" >2</th>
        <td id="T_dd1e2328_21f7_11e7_995e_186590cd1c87row2_col0" class="data row2 col0" >0</td>
        <td id="T_dd1e2328_21f7_11e7_995e_186590cd1c87row2_col1" class="data row2 col1" >-1.047</td>
        <td id="T_dd1e2328_21f7_11e7_995e_186590cd1c87row2_col2" class="data row2 col2" >-0.9169</td>
    </tr></tbody>
</table>
Was this page helpful?
0 / 5 - 0 ratings