0

I'm trying to create nice slides using jupyter notebook and RISE. One of my objectives is to display a pandas-dataframe in a Markdown cell in order to have some styling flexibility.

I am using the following code to display my dataframe in a Markdown cell:

{{Markdown(display(df_x))}}

After running this line, I get the following result:

image of dataframe displayed

I would like to get rid of the text printed below my dataframe (<IPython.core.display.Markdown object>).

I still haven't found a way to achieve this. Could someone give me a hand?

This is the library I'm working with:

from IPython.display import display
robperch
  • 45
  • 1
  • 5

1 Answers1

0

Not familiar with Markdown class so not sure why you need that but this text printed in the output cell is coming from the fact that this Markdown class is returning and object and since you're not assigning it to any variable the default behavior for the notebook is to run something like str(your_object) which correctly returns <IPython.core.display.Markdown object>. So the easiest workaround would be to just assign it to some variable like this:

dummy_var = Markdown(display(df_x))

# or better yet:

_ = Markdown(display(df_x))
Karol Żak
  • 2,158
  • 20
  • 24
  • 1
    It worked great! I actually modified my code this way and it worked like a charm: `{ { dummy_var = Markdown( display( df_x ) ) } }` – robperch Apr 05 '21 at 22:49
  • Glad it works @Roberto919 - if my answer solved your problem then please upvote it and mark it as a solution, thanks! – Karol Żak Apr 06 '21 at 12:54
  • Sorry for the late answer @Karol Żak ... your answer did help me a lot and I have already upvoted it. However, my reputation is too low for the upvote to be registered :( Sorry – robperch Jul 08 '21 at 01:03