How do I hide the column labels via pandas style? There is a hide_index() method that removes the index row, unfortunately the hide_column() label removes the entire column (both the header and the data). I just want to hide the headers. thanks!
How do I hide the column labels via pandas style? There is a hide_index() method that removes the index row, unfortunately the hide_column() label removes the entire column (both the header and the data). I just want to hide the headers. thanks!
set_table_stylesYou can set the style for the table. Docs
df = pd.DataFrame(1, range(3), ['Look', 'At', 'My', 'Header'])
df.style
df.style.set_table_styles([
{'selector': 'thead', 'props': [('display', 'none')]}
])
As part of the Styler Enhancements in pandas 1.3.0 hide_columns() with no subset will simply hide the columns from display, no longer removing the associated column data.
import pandas as pd
df = pd.DataFrame(1, range(3), ['Look', 'At', 'My', 'Header'])
df.style.hide_columns()
In 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')