Jupyter notebook display two pandas tables side by side

后端 未结 12 1941
迷失自我
迷失自我 2020-12-04 04:56

I have two pandas dataframes and I would like to display them in Jupyter notebook.

Doing something like:

display(df1)
display(df2)

12条回答
  •  生来不讨喜
    2020-12-04 05:55

    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(''.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;
    }
    """
    

提交回复
热议问题