dartdog dartdog - 1 year ago 59
Python Question

How to format output on Ipython Notebook with Pandas to get side-by-side 2-up tables?

Loving Ipython Notebook and with the new NBconvert getting some great looking output but wondering if there might be a way to improve things even more..
I produce a series of describe stats blocks that show up like: one after the next..(more than illustrated) Is there any way to get them to be two -up row by row?? the current output stretches out on the page and I'd like to get a more compact representation. It also may be desirable to reduce the font size for spacing?

INVERNESS
LIST_PRICE SOLD_PRICE
count 1693.000000 957.000000
mean 280827.088600 252088.333333
std 115580.920634 91553.077871
min 84900.000000 79400.000000
25% 208900.000000 195880.000000
50% 249900.000000 231795.000000
75% 319900.000000 285000.000000
max 989900.000000 800000.000000

Median Values:
LIST_PRICE 249900
SOLD_PRICE 231795
dtype: float64 Axes(0.125,0.125;0.775x0.775)

RIVERCHASE
LIST_PRICE SOLD_PRICE
count 2044.000000 1157.000000
mean 329096.447652 294856.720830
std 168384.682832 122089.475792
min 58000.000000 58000.000000
25% 234000.000000 216500.000000
50% 295450.000000 267900.000000
75% 379900.000000 349900.000000
max 2950000.000000 1400000.000000

Median Values:
LIST_PRICE 295450
SOLD_PRICE 267900

Answer Source

You could achieve this by concatenating the results of the describe method for each DataFrame.

For instance if the INVERNESS DataFrame was named df and RIVERCHASE df2:

pd.concat([df.describe(), df2.describe()], keys = ['INVERNESS', 'RIVERCHASE'], axis = 1)