Closed ghuname closed 4 years ago
So two things -- what output format are you trying to convert to (what's the command you are using with nbconvert) and have you run it with nbconvert 6.0?
What you are seeing is the html output of the dataframe as plain text instead of rendered text. If you're outputting to html this should render nicely.
@MSeal, I am trying to export to pdf with --to pdf
option.
Furthermore, if I understood correctly, there is no support for panda stylers conversion latex/pdf at all.
For example, df.style.set_properties(**{'background-color': 'yellow'})
produces styler object that knows how to represent itself in html format, but doesn't know how to represent itself in latex at all.
There is no _repr_latex_
method on styler object.
At the moment, I am trying to subclass pandas styler object (from pandas.io.formats.style import Styler
) in order to add _repr_latex_
method in which I will iterate through dataframe and generate latex code by myself.
So, I will use styler object like MyStyler(df, section_caption='section', table_caption='table', table_header_bold=True...)
.
I don't see any other option. If someone has more experience than me, please share your ideas.
Yes latex conversion doesn't respect HTML attributes in this path afaik. However you could try using the new webpdf
conversion path to generate the PDF from a headless Chromium process. That would preserve HTML styling in export.
I confirm that this works well with --to webpdf
:
Closing as answered!
What I have to install on centos 7 in order to be able to use --to webpdf?
Have you tried the webpdf installation instructions yet? I don't expect there needs to be anything more for centos but I haven't explicitly tested that OS for that capability.
I tried to print to pdf from chrome and result wasn't good so I assume that this is not the solution.
@ghuname just use the webpdf exporter of nbconvert, and you should get the kind of result that I included as a screenshot above.
Actually your demo highlights another issue with the webpdf conversion. The code cell in your demo is truncated on the right side. This seems to be a significant problem as it affects the readability of the code. Could we reopen the issue to address this truncation problem?
I have a simple dataframe that I would like to color dynamically by using df.style.
I generated a dataframe with:
Now I would like to use colors.
If I render last line with:
df.style.background_gradient(cmap=cm).hide_index().highlight_max(color='blue').highlight_min().render()
I get:'<style type="text/css" >\n#T_e7a9a29a_f734_11ea_92c3_0242ac110002row0_col0{\n background-color: #e5ffe5;\n color: #000000;\n background-color: yellow;\n }#T_e7a9a29a_f734_11ea_92c3_0242ac110002row1_col0{\n background-color: #ccf1cc;\n color: #000000;\n }#T_e7a9a29a_f734_11ea_92c3_0242ac110002row2_col0{\n background-color: #b3e3b3;\n color: #000000;\n }#T_e7a9a29a_f734_11ea_92c3_0242ac110002row3_col0{\n background-color: #99d599;\n color: #000000;\n }#T_e7a9a29a_f734_11ea_92c3_0242ac110002row4_col0{\n background-color: #80c780;\n color: #000000;\n }#T_e7a9a29a_f734_11ea_92c3_0242ac110002row5_col0{\n background-color: #66b866;\n color: #000000;\n }#T_e7a9a29a_f734_11ea_92c3_0242ac110002row6_col0{\n background-color: #4daa4d;\n color: #000000;\n }#T_e7a9a29a_f734_11ea_92c3_0242ac110002row7_col0{\n background-color: #329c32;\n color: #000000;\n }#T_e7a9a29a_f734_11ea_92c3_0242ac110002row8_col0{\n background-color: #198e19;\n color: #000000;\n }#T_e7a9a29a_f734_11ea_92c3_0242ac110002row9_col0{\n background-color: #008000;\n color: #f1f1f1;\n background-color: blue;\n }</style><table id="T_e7a9a29a_f734_11ea_92c3_0242ac110002" ><thead> <tr> <th class="col_heading level0 col0" >a</th> <th class="col_heading level0 col1" >b</th> </tr></thead><tbody>\n <tr>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row0_col0" class="data row0 col0" >1</td>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row0_col1" class="data row0 col1" >A</td>\n </tr>\n <tr>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row1_col0" class="data row1 col0" >2</td>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row1_col1" class="data row1 col1" >B</td>\n </tr>\n <tr>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row2_col0" class="data row2 col0" >3</td>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row2_col1" class="data row2 col1" >C</td>\n </tr>\n <tr>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row3_col0" class="data row3 col0" >4</td>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row3_col1" class="data row3 col1" >D</td>\n </tr>\n <tr>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row4_col0" class="data row4 col0" >5</td>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row4_col1" class="data row4 col1" >E</td>\n </tr>\n <tr>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row5_col0" class="data row5 col0" >6</td>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row5_col1" class="data row5 col1" >F</td>\n </tr>\n <tr>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row6_col0" class="data row6 col0" >7</td>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row6_col1" class="data row6 col1" >G</td>\n </tr>\n <tr>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row7_col0" class="data row7 col0" >8</td>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row7_col1" class="data row7 col1" >H</td>\n </tr>\n <tr>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row8_col0" class="data row8 col0" >9</td>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row8_col1" class="data row8 col1" >I</td>\n </tr>\n <tr>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row9_col0" class="data row9 col0" >10</td>\n <td id="T_e7a9a29a_f734_11ea_92c3_0242ac110002row9_col1" class="data row9 col1" >J</td>\n </tr>\n </tbody></table>'
Is this bug or feature?
Here is the notebook:
nbconvert version: 5.6.1