如何在Pandas Jupyter Lab中获取文本省略号



我正在jupyter实验室中显示pandas dataframe。有些单元的文字很长,如果我放: df.style它将使行很高。设置:df.style.set_table_styles([dict(selector="tr",props=[('text-overflow', 'ellipsis'),('overflow', 'hidden'), ('height', '20px')])])不幸没有效果。

我确认通过将高度设置为高值,可以使用并更改行高度来使用设置。在某种程度上,只有高度的最小值,由单元格中的文本量确定。

将其设置在'td'上,并添加"白空间:nowrap"至少使行的高度相同,但是现在列确实宽了:

df.style.set_table_styles([dict(selector="td",props=[('text-overflow', 'ellipsis'),('overflow', 'hidden'), ('white-space','nowrap'), ('height', '20px')])])

我也有类似的问题。试图使用PANDAS样式来使HTML/CSS代码在烧瓶应用程序中很好地渲染,并且列的文字溢出。我的解决方案是在HTML和随附的JS代码中包括" Text-Overflow:Ellipsis"类。

在某物_something **。

<div id="table_id" class="table table-striped hover text-overflow: ellipsis"> {{ pd_DataFrame_style_rendered | safe }} </div>

在某种程度上**。

.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  /*white-space: nowrap;*/
}

希望这会有所帮助。

最新更新