0

I'm trying to display a dataframe with a specific style twice (output twice on jupyter notebook). It doesn't show up when I use a for loop.

## having already created dataframe df

for i in range(2):
      df.style.set_table_styles([{'selector' : '','props' : [('border',
                                        '10px solid yellow')]}])

However it works when I do this:

df.style.set_table_styles([{'selector' : '','props' : [('border',
                                        '10px solid yellow')]}])

df.style.set_table_styles([{'selector' : '','props' : [('border',
                                        '10px solid yellow')]}])

How can I get it to work in a for loop?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
amajester
  • 55
  • 4

2 Answers2

3

You can use display:

for i in range(2):
  display(df.style.set_table_styles([{'selector' : '','props' : [('border',
                                    '10px solid yellow')]}]))
notiv
  • 441
  • 5
  • 12
3

By default, Jupyter cells only display the last expression output.

To change this behavior and display all expressions in a cell when you run it, you can add this line at the beginning of your notebook:

from IPython.core.interactiveshell import InteractiveShell

InteractiveShell.ast_node_interactivity = "all"  # default='last_expr'
Laurent
  • 12,287
  • 7
  • 21
  • 37