1

In Jupyter, I am running a long-running computation.

I want to show a Pandas table with the top 25 rows. The top 25 may update each iteration.

However, I don't want to show many Pandas tables. I want to delete / update the existing displayed Pandas table.

How is this possible?

This approach seems usable for matplotlibs but not pandas pretty tables.

Joseph Turian
  • 15,430
  • 14
  • 47
  • 62

1 Answers1

1

You can use clear_output and display the dataframe:

from IPython.display import display, clear_output
# this is just to simulate the delay
import time

i = 1
while i<10:
    time.sleep(1)
    df = pd.DataFrame(np.random.rand(4,3))
    clear_output(wait=True)
    display(df)
    i += 1
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
  • 1
    Thank you. This is also this: https://stackoverflow.com/questions/24816237/ipython-notebook-clear-cell-output-in-code And this even more advanced usage: https://github.com/jupyter-widgets/ipywidgets/issues/1744#issuecomment-335179855 – Joseph Turian Sep 12 '22 at 03:57