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.

Climacus
  • 113
  • 1
  • 1
  • 6

1 Answers1

13

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

dan_g
  • 2,712
  • 5
  • 25
  • 44