jupyter-notebook: print fine table in a cycle

Question:

When I input a name of dataframe in jupyter-notebook, it prints a pretty table:

fail_data

enter image description here

It can even recognize the TeX notation.

But when I need to print the data in the cycle, the output looks not so good:

fail_data_gr = fail_data.groupby('test_name')
for k, v in fail_data_gr:
    print(v)

enter image description here

How to make this output looking like the first one?

Asked By: Michael

||

Answers:

Displaying in jupyter notebooks delegate to the IPython.display module. When printing inside a loop, print dumps the __str__ representation of the DataFrame, which does no special rendering.

So, in summary, change

for k, v in fail_data_gr:
    print(v)

to

from IPython.display import display
for k, v in fail_data_gr:
    display(v)
Answered By: cs95
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.