11

I've seen a lot of very helpful posts on using prettyprint and such; they have been very helpful -- thanks.

What I'm wondering if there is anyway to print a dataframe from a function and have it output as "prettily" as Jupyter notebook does:

Jupyter notebook display

My main reason is I would like to use pandas's styling functions to highlight/shade. I also want to print from a function and not a Jupyter code box if possible as I have some packages I have created and I may want to spit out 2 or more dataframes in a call.

Using prettyprint or print() alone gives a purely text output:

>       Year      Month  Mean Maximum Temperature Albury  \ 
> 672   1955    January                             30.8    
> 673   1955   February                             27.9    
> 674   1955      March                             26.7
> 675   1955      April                             22.1  
> ....

I'd like the graphical output. Not using print(), e.g.

historic_dataframe

does nothing if within a function.

My thanks for your time.

0

1 Answer 1

14

Use display from IPython instead of print

import pandas as pd
from IPython.display import display

df = pd.DataFrame(pd.np.random.random((10, 10)))
display(df)

display docs

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, Dan G; that is great! And sorry for not finding the earlier question and asking a duplicate.
The classical case. I clicked on upvote, since I have not seen that it was marked as duplicate...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.