熊猫Styler.如何忽略呈现的HTML中的索引列

Mar*_*ski 7 css python pandas

我正在尝试使用在电子邮件中呈现样式器生成的字符串.似乎很难让这个忽略数据框索引.

table_styles = [dict(selector="tbody tr th", props=[("display", "none")]),
st=df.style.set_table_styles(table_styles)
st.render()
Run Code Online (Sandbox Code Playgroud)

我已经能够使用display none CSS设置使其工作,但它在基于CSS支持级别的不同设备上的工作方式不同.
有没有办法让索引有效载荷消失?

pg2*_*455 1

我认为我有与您相同的解决方案,并且我面临着与您相同的问题(不同设备上的显示不同)。我只是在这里写下部分解决方案,以帮助正在寻找方法的人。

如果这样做,html.render().split('\n')您将能够获得与第一列和索引相关的类结构(如果您已经使用了 resent_index)。

然后可以使用显示的 CSS 属性定义样式以消除这些列。

# define the style related to first column and index here
# first-element : when index =True, 
# second element: default index of the table generated by the Style
styles = [ 
  dict(selector = ".col0", props = [('display', 'none')]), 
  dict(selector = "th:first-child", props = [('display', 'none')])
 ]

 # set the table styles here
 table.set_table_styles(styles)
Run Code Online (Sandbox Code Playgroud)