在 iPython Notebook 的 HTML 表中打印 2 Python Pandas DataFrame
Printing 2 Python Pandas DataFrame in HTML Tables in iPython Notebook
问题:如何从 1 iPython 笔记本行中打印 2 个 DataFrame table,这样两个 table 都是以漂亮的 table 格式显示?
以下仅打印第二个,print df.head()
不会生成漂亮的 table。
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()
以下内容无法生成所需的 table:
print df.head()
print df2.head()
在 IPython 笔记本中,除非明确打印或显示,否则仅显示单元格最后一行的结果。
部分选项:
- 将第二个
df.head()
放在下一个单元格中
- 使用
print df
显式打印数据框 -> 但是,这给出了文本表示而不是 html 表示
使用display(df)
显式显示数据帧,此将给出与数据帧如何显示相同的html表示默认。为此,您需要以下导入:
from IPython.display import display
问题:如何从 1 iPython 笔记本行中打印 2 个 DataFrame table,这样两个 table 都是以漂亮的 table 格式显示?
以下仅打印第二个,print df.head()
不会生成漂亮的 table。
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()
以下内容无法生成所需的 table:
print df.head()
print df2.head()
在 IPython 笔记本中,除非明确打印或显示,否则仅显示单元格最后一行的结果。
部分选项:
- 将第二个
df.head()
放在下一个单元格中 - 使用
print df
显式打印数据框 -> 但是,这给出了文本表示而不是 html 表示 使用
display(df)
显式显示数据帧,此将给出与数据帧如何显示相同的html表示默认。为此,您需要以下导入:from IPython.display import display