【问题标题】:Printing 2 Python Pandas DataFrame in HTML Tables in iPython Notebook在 iPython Notebook 的 HTML 表中打印 2 个 Python Pandas DataFrame
【发布时间】:2015-07-11 10:55:48
【问题描述】:

问题:如何从 1 个 iPython Notebook 行一起打印 2 个 DataFrame 表,从而使两个表都以漂亮的表格格式显示?

以下仅打印第二个,print df.head() 不会生成漂亮的表格。

df = pd.DataFrame(np.random.randn(6,4), index=pd.date_range('20150101', periods=6), columns=list('ABCD'))
df2 = pd.DataFrame(np.random.randn(6,4), index=pd.date_range('20150101', periods=6), columns=list('WXYZ'))


df.head()
df2.head()

以下内容不会生成所需的漂亮表格:

print df.head()
print df2.head()

【问题讨论】:

  • 你想在这里得到最底层的答案吗:stackoverflow.com/questions/28966780/… 如果是这样,我将作为重复关闭
  • df.head(), df2.head()
  • 或者你可以使用print
  • @joris print df.head() 不会生成漂亮的表格
  • from IPython.display import display,然后使用display(df.head())

标签: python pandas ipython ipython-notebook


【解决方案1】:

在 IPython 笔记本中,仅显示单元格最后一行的结果,除非明确打印或显示。

一些选项:

  • 将第二个df.head() 放在下一个单元格中
  • 使用 print df 显式打印数据框 -> 但是,这给出了文本表示而不是 html 表示
  • 使用display(df) 显式显示数据框,此提供与默认显示数据框的方式相同的html 表示。为此,您需要以下导入:

    from IPython.display import display
    

【讨论】:

    猜你喜欢
    • 2015-03-04
    • 2014-04-04
    • 2015-06-28
    • 2019-12-07
    • 2015-01-08
    相关资源
    最近更新 更多