问题描述
我有两个 Pandas 数据框,我想在 Jupyter notebook 中显示它们.
做类似的事情:
display(df1)显示(df2)
将它们显示在另一个下方:
我想在第一个数据框的右侧有第二个数据框.有
当然,您可以根据需要进一步自定义 CSS.
如果您希望只针对一个单元格的输出,请尝试使用 :nth-child()
选择器.例如,此代码将仅修改笔记本中第 5 个单元格的输出的 CSS:
CSS = """div.cell:nth-child(5) .output {弹性方向:行;}"""
I have two pandas dataframes and I would like to display them in Jupyter notebook.
Doing something like:
display(df1)
display(df2)
Shows them one below another:
I would like to have a second dataframe on the right of the first one. There is a similar question, but it looks like there a person is satisfied either with merging them in one dataframe of showing the difference between them.
This will not work for me. In my case dataframes can represent completely different (non-comparable elements) and the size of them can be different. Thus my main goal is to save space.
You could override the CSS of the output code. It uses flex-direction: column
by default. Try changing it to row
instead. Here's an example:
import pandas as pd
import numpy as np
from IPython.display import display, HTML
CSS = """
.output {
flex-direction: row;
}
"""
HTML('<style>{}</style>'.format(CSS))
You could, of course, customize the CSS further as you wish.
If you wish to target only one cell's output, try using the :nth-child()
selector. For example, this code will modify the CSS of the output of only the 5th cell in the notebook:
CSS = """
div.cell:nth-child(5) .output {
flex-direction: row;
}
"""
这篇关于Jupyter 笔记本并排显示两个 Pandas 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!