You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 11:17:03