在JupyterHub中使用display和HTML展示内容时如何消除警告?
解决Pandas Styler废弃方法警告问题
在JupyterHub中使用IPython.display包展示数据时,数据显示正常,但收到两条废弃方法警告:
/tmp/ipykernel_8683/279239772.py:8: FutureWarning: this method is deprecated in favour of `Styler.hide(axis='index')` counts[['ani','size']].sort_values(by=['size'], ascending=False).style.hide_index().render() + /tmp/ipykernel_8683/279239772.py:8: FutureWarning: this method is deprecated in favour of `Styler.to_html()` counts[['ani','size']].sort_values(by=['size'], ascending=False).style.hide_index().render() +原展示代码:
display(HTML("<div style='height: 200px; overflow: auto; width: fit-content'>" + counts[['ani','size']].sort_values(by=['size'], ascending=False).style.hide_index().render() + "</div>"))
解决方案
- 替换废弃的
hide_index()方法:使用官方推荐的hide(axis='index')替代 - 替换废弃的
render()方法:使用官方指定的to_html()替代,功能与原方法完全一致
修改后的完整代码:
display(HTML("<div style='height: 200px; overflow: auto; width: fit-content'>" + counts[['ani','size']].sort_values(by=['size'], ascending=False).style.hide(axis='index').to_html() + "</div>"))
内容的提问来源于stack exchange,提问作者ilikawa
相关产品推荐
相关产品推荐

