Fix tabledf.
This commit is contained in:
parent
f3c3a6185a
commit
8aa3d06b19
@ -61,8 +61,7 @@ class tabledf(table):
|
||||
def __init__(self, df, header=None, multilevels=False, fmt=None, **kargs):
|
||||
super().__init__(**kargs)
|
||||
if header is None:
|
||||
header = self.create_header(df)
|
||||
multilevels = True
|
||||
multilevels, header = self.create_header(df)
|
||||
df = df.reset_index()
|
||||
if multilevels:
|
||||
ncols = len(header[-1])
|
||||
@ -74,13 +73,13 @@ class tabledf(table):
|
||||
else:
|
||||
tab.addrow(header)
|
||||
tab.addhline()
|
||||
tab.addrows(df.as_matrix(), fmt=fmt)
|
||||
tab.addrows(df.astype(object).values, fmt=fmt)
|
||||
self.add(tab)
|
||||
|
||||
def create_header(self, df):
|
||||
cols = df.columns
|
||||
if not isinstance(cols, pd.MultiIndex):
|
||||
return df.columns
|
||||
return False, list(df.columns)
|
||||
idx = df.index.names
|
||||
header = []
|
||||
for levels, labels in zip(cols.levels, cols.labels):
|
||||
@ -89,4 +88,4 @@ class tabledf(table):
|
||||
tmp.append(multicolumn(len(list(g)), levels[i]))
|
||||
header.append(tmp)
|
||||
header[-1] = idx + header[-1][1:] # Update last row
|
||||
return header
|
||||
return True, header
|
||||
|
Loading…
Reference in New Issue
Block a user