'pandas style - how to hide the column labels?

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!



Solution 1:[1]

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()

styled table with no header (new hide_columns behaviour)


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')

styled table with no header (using hide(axis='columns'))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1