Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 940
user3198755 Avatar asked Oct 21 '17 03:10

user3198755


1 Answers

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(''))
like image 51
cs95 Avatar answered Sep 19 '22 12:09

cs95