I have a Pandas series (slice of larger DF corresponding to a single record) that I would like to display as html. While i can convert the Series to a DataFrame and use the .to_html()
function this will result in a two-column html output. To save space/give a better aspect ratio I would like to return a four- or six-column HTML table where the series has been wrapped into two or three sets of index-value columns, like so.
import pandas as pd
s = pd.Series( [12,34,56,78,54,77], index=['a', 'b', 'c', 'd', 'e','f'])
#pd.DataFrame(s).to_html()
#will yield 2 column hmtl-ed output
# I would like a format like this:
a 12 d 78
b 34 e 54
c 56 f 77
This is what I have currently:
x = s.reshape((3,2))
y = s.index.reshape((3,2))
new = [ ]
for i in range(len(x)):
new.append(y[i])
new.append(x[i])
z = pd.DataFrame(new)
z.T.to_html(header=False, index=False)
Is there a better way that I might have missed?
thanks zach cp