8

In Jupyter notebooks with many Pandas Dataframes, is there a way to set default Style options for all dataframes? Essentially to avoid boilerplate.

For example Hiding-the-Index-or-Columns with df.style.hide_index() for all dataframes.

Yes, I could write wrapper function, but thinking more of something like pd.options.display

Martin Thøgersen
  • 1,538
  • 18
  • 33

1 Answers1

0

if you are using lots of dataframes you could find dataframes in your workspace and then apply style to each one of them

workspace = dir() #gets all variables in workspace
for variable_name in workspace:
    excec( f'var_type=type({variable_name})' ) #since we have access to only the names of variables we'll use exec
    if var_type== pd.Dataframe():#check to see if the variable is of type dataframe
        #apply style here
  • 1
    This solution looks okay, but it only solves the problem completely if the styling only matters after every dataframe is created. Otherwise, it would have to be run on every dataframe creation, and then calling a wrapper is simpler. – Vincent Rupp May 16 '23 at 19:19