0

I have a data frame and for each group in it I want to display a data frame specific only for this group and plot in Jupiter notebook.

for name, group in building_info.groupby(['building_category']):
    display(group)
    fig, ax = plt.subplots(nrows=1, ncols=1,figsize=(13,5))
    sns.displot(group.num_people, ax = ax)

First it will display all data frames for each group and only then it will produce the plots. I would like to have that display(group) is directly followed by a plot, so that I have a direct comparisons of the data with a plot.

kkk
  • 183
  • 1
  • 9
  • Have you read [this](https://stackoverflow.com/questions/44741809/in-an-html-table-how-to-add-text-beside-plot-in-jupyter-notebook-using-python) or [this](https://stackoverflow.com/questions/32423322/how-to-display-a-text-paragraph-next-to-figure-in-jupyter-ipython-notebook)? Could you try that approach and if it fails ask specifically about the problem you encounter? – ImportanceOfBeingErnest Sep 23 '17 at 20:38
  • Also, [this](https://stackoverflow.com/questions/45286696/how-to-display-dataframe-next-to-plot-in-jupyter-notebook) may be an alternative approach. – ImportanceOfBeingErnest Sep 23 '17 at 20:39

1 Answers1

1

If you're using Jupyter you could try importing this library:

# Print multiple objects to screen in same shell 
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

This allows you to print the dataframe and a plot right below it:

# Make dataframe
data = {'a' : np.random.randint(0, 10, size = 10),
        'b' : np.random.randint(0, 10, size = 10),
        'c' : np.random.randint(0, 10, size = 10)}

df = pd.DataFrame(data)

# Show df
df
# show plot
df.plot()
plt.show()
# Show df again
df
# Show plot again
df.plot()
plt.show()

Returns:

multiple objects

Ian Thompson
  • 2,914
  • 2
  • 18
  • 31