在 pandas 中并排显示两个数据框 [英] Display two dataframes side by side in Pandas

查看:50
本文介绍了在 pandas 中并排显示两个数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据帧,每个数据帧都有10行,我试图使用并排显示它们

I have two dataframes each with 10 rows and I am trying to display them side by side using

print df, df2

但是它给出了这样的输出

But it is giving output like this

               Last       High   High_Perc
170     0.01324000 0.03822200 65.36026372
194     0.00029897 0.00052040 42.54996157
163     0.00033695 0.00058000 41.90517241
130     0.00176639 0.00282100 37.38426090
78      0.00003501 0.00005552 36.94164265
13      0.00009590 0.00014814 35.26393952
58      0.00002149 0.00003228 33.42627014
124     0.00009151 0.00013700 33.20437956
32      0.00059649 0.00089000 32.97865169         Last        Low    Low_Perc
170     0.01324000 0.01204685 65.36026372
194     0.00029897 0.00029000 42.54996157
163     0.00033695 0.00032270 41.90517241
130     0.00176639 0.00171874 37.38426090
78      0.00003501 0.00003450 36.94164265
13      0.00009590 0.00009200 35.26393952
58      0.00002149 0.00002140 33.42627014
124     0.00009151 0.00009000 33.20437956
32      0.00059649 0.00059001 32.97865169

我尝试了以下选项,但仍无法并排设置

I have tried the below options but I am still not able to set them side by side

    pd.set_option('display.max_rows', 500)
    pd.set_option('display.max_columns', 500)
    pd.set_option('display.width', 10000)
    pd.set_option('display.float_format', lambda x: '%.8f' % x)
    pd.options.display.max_columns = None

请帮助

推荐答案

不幸的是, print 不知道在打印数据帧时并排平铺.它调用每个 df str 并逐一打印.

Unfortunately, print does not know to tile the dataframes side-by-side when printing them out. It calls each df's str and prints them one by one.

尝试在打印之前进行串联:

Try concatenation before the print:

print pd.concat([df.reset_index(drop=1).add_suffix('_1'),
            df2.reset_index(drop=1).add_suffix('_2')], axis=1).fillna('')

这篇关于在 pandas 中并排显示两个数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆