简体   繁体   English

在熊猫中并排显示两个数据框

[英]Display two dataframes side by side in Pandas

I have two dataframes each with 10 rows and I am trying to display them side by side using 我有两个数据帧,每个数据帧有10行,我正在尝试使用并排显示它们

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

Please help 请帮忙

Unfortunately, print does not know to tile the dataframes side-by-side when printing them out. 不幸的是, print不知道在print数据帧时并排平铺它们。 It calls each df 's str and prints them one by one. 它调用每个dfstr并一一打印。

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('')

Try something like this: 尝试这样的事情:

import izip_longest from itertools
print '\n'.join([ia + ib from ia, ib in izip_longest(
    str(df).split('\n'), str(df2).split('\n'), fillvalue = '')])

If the last is longer, you can adjust the length of the fill value. 如果最后一个较长,则可以调整填充值的长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM