Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

python - 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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...