PalimPalim
PalimPalim

Reputation: 3058

jupyter print plot and dataframe in order, for loop

I want to print the dataframe and plots in the order as in the code in my jupyter notebook:

Currently, they are printed as:

from IPython.display import display
import matplotlib.pyplot as plt

df = pd.DataFrame({'x': range(5), 'y': range(5)})

for i in range(2):
    display(df)
    display(df.plot())

enter image description here

Upvotes: 6

Views: 1495

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150785

Force plt.show after you plot:

for i in range(2):
    display(df)
    df.plot()
    plt.show()

Upvotes: 9

Related Questions