jupyter main函数_像Jupyter一样很好地从函数打印数据框

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:

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.

解决方案

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值