在 iPython Notebook 中将 DataFrame 显示为表格 [英] Show DataFrame as table in iPython Notebook

查看:69
本文介绍了在 iPython Notebook 中将 DataFrame 显示为表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 iPython 笔记本.当我这样做时:

I am using iPython notebook. When I do this:

df

我得到了一张漂亮的带单元格的表格.但是,如果我这样做:

I get a beautiful table with cells. However, if i do this:

df1
df2 

它不会打印第一个漂亮的表格.如果我试试这个:

it doesn't print the first beautiful table. If I try this:

print df1
print df2

它以不同的格式打印表格,该格式会溢出列并使输出非常高.

It prints out the table in a different format that spills columns over and makes the output very tall.

有没有办法强制它打印出两个数据集的漂亮表格?

Is there a way to force it to print out the beautiful tables for both datasets?

推荐答案

您需要使用 IPython 显示模块中的 HTML()display() 函数:

You'll need to use the HTML() or display() functions from IPython's display module:

from IPython.display import display, HTML

# Assuming that dataframes df1 and df2 are already defined:
print "Dataframe 1:"
display(df1)
print "Dataframe 2:"
display(HTML(df2.to_html()))

请注意,如果您只是print df1.to_html(),您将获得未渲染的原始 HTML.

Note that if you just print df1.to_html() you'll get the raw, unrendered HTML.

您也可以从 IPython.core.display 导入,效果相同

You can also import from IPython.core.display with the same effect

这篇关于在 iPython Notebook 中将 DataFrame 显示为表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆