Jupyter notebook display two pandas tables side by side

后端 未结 12 1946
迷失自我
迷失自我 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 05:36

    Here is Jake Vanderplas' solution I came across just the other day:

    import numpy as np
    import pandas as pd
    
    class display(object):
        """Display HTML representation of multiple objects"""
        template = """

    {0}

    {1}
    """ def __init__(self, *args): self.args = args def _repr_html_(self): return '\n'.join(self.template.format(a, eval(a)._repr_html_()) for a in self.args) def __repr__(self): return '\n\n'.join(a + '\n' + repr(eval(a)) for a in self.args)

    Credit: https://github.com/jakevdp/PythonDataScienceHandbook/blob/master/notebooks/03.08-Aggregation-and-Grouping.ipynb

提交回复
热议问题