如错误消息所示,您正在尝试
Dataframe.to_html()在
Styler对象上使用方法,因为它
df.style.apply返回的是
Styler对象而不是
Dataframe。
该文件说,你可以使用该
render()方法来
呈现 的HTML。
像这样:
style1 = df.style.apply(highlight_greaterthan,threshold=1.0,column=['C','B'], axis=1)df_html = style1.render()
的输出为
style1.render():
<style type="text/css" > #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col0 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col1 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col2 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col3 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col4 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col0 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col1 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col2 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col3 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col4 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col0 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col1 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col2 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col3 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col4 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col0 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col1 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col2 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col3 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col4 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col0 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col1 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col2 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col3 { background-color: yellow; } #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col4 { background-color: yellow; }</style> <table id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3" > <thead> <tr> <th ></th> <th >A</th> <th >B</th> <th >C</th> <th >D</th> <th >E</th> </tr></thead> <tbody> <tr> <th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row0" >0</th> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col0" >1</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col1" >1.32921</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col2" >nan</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col3" >-0.31628</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col4" >-0.99081</td> </tr> <tr> <th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row1" >1</th> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row1_col0" >2</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row1_col1" >-1.07082</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row1_col2" >-1.43871</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row1_col3" >0.564417</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row1_col4" >0.295722</td> </tr> <tr> <th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row2" >2</th> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row2_col0" >3</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row2_col1" >-1.6264</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row2_col2" >0.219565</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row2_col3" >0.678805</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row2_col4" >1.88927</td> </tr> <tr> <th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row3" >3</th> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row3_col0" >4</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row3_col1" >0.961538</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row3_col2" >0.104011</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row3_col3" >-0.481165</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row3_col4" >0.850229</td> </tr> <tr> <th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row4" >4</th> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col0" >5</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col1" >1.45342</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col2" >1.05774</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col3" >0.165562</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col4" >0.515018</td> </tr> <tr> <th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row5" >5</th> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row5_col0" >6</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row5_col1" >-1.33694</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row5_col2" >0.562861</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row5_col3" >1.39285</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row5_col4" >-0.063328</td> </tr> <tr> <th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row6" >6</th> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col0" >7</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col1" >0.121668</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col2" >1.2076</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col3" >-0.00204021</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col4" >1.6278</td> </tr> <tr> <th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row7" >7</th> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col0" >8</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col1" >0.354493</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col2" >1.03753</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col3" >-0.385684</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col4" >0.519818</td> </tr> <tr> <th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row8" >8</th> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col0" >9</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col1" >1.68658</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col2" >-1.32596</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col3" >1.42898</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col4" >-2.08935</td> </tr> <tr> <th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row9" >9</th> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row9_col0" >10</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row9_col1" >-0.12982</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row9_col2" >0.631523</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row9_col3" >-0.586538</td> <td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row9_col4" >0.29072</td> </tr></tbody> </table>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)