Jupyter notebook display two pandas tables side by side

后端 未结 12 1945
迷失自我
迷失自我 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:48

    Extension of antony's answer If you want to limit de visualization of tables to some numer of blocks by row, use the maxTables variable.

    def mydisplay(dfs, names=[]):
    
        count = 0
        maxTables = 6
    
        if not names:
            names = [x for x in range(len(dfs))]
    
        html_str = ''
        html_th = ''
        html_td = ''
    
        for df, name in zip(dfs, names):
            if count <= (maxTables):
                html_th += (''.join(f'{name}'))
                html_td += (''.join(f' {df.to_html(index=False)}'))
                count += 1
            else:
                html_str += f'{html_th}{html_td}'
                html_th = f'{name}'
                html_td = f' {df.to_html(index=False)}'
                count = 0
    
    
        if count != 0:
            html_str += f'{html_th}{html_td}'
    
    
        html_str += f'{html_str}
    ' html_str = html_str.replace('table','table style="display:inline"') display_html(html_str, raw=True)

提交回复
热议问题