pandas style - 如何隐藏列标签?

pandas style - how to hide the column labels?

如何通过 pandas 样式隐藏列标签?有一个删除索引行的 hide_index() 方法,不幸的是 hide_column() 标签删除了整个列(header 和数据)。我只想隐藏 headers。谢谢!

set_table_styles

您可以为 table 设置 styleDocs

设置

df = pd.DataFrame(1, range(3), ['Look', 'At', 'My', 'Header'])

df.style

df.style.set_table_styles([
    {'selector': 'thead', 'props': [('display', 'none')]}
])

作为 pandas 1.3.0 hide_columns() 中 Styler 增强功能的一部分,没有子集将简单地隐藏显示的列,不再删除关联的列数据。

import pandas as pd

df = pd.DataFrame(1, range(3), ['Look', 'At', 'My', 'Header'])
df.style.hide_columns()


在 pandas 1.4.0 hide_columns was deprecated (GH43758) in favour of hide with axis=..., but keeps the same behaviour as 1.3.0's hide_columns:

import pandas as pd

df = pd.DataFrame(1, range(3), ['Look', 'At', 'My', 'Header'])
df.style.hide(axis='columns')