From 8aa3d06b199e48ce973b150f8c5f3054a6044577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Thu, 20 Jul 2017 11:02:29 +0200 Subject: [PATCH] Fix tabledf. --- pyltk/table.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pyltk/table.py b/pyltk/table.py index f824d25..ad466c4 100644 --- a/pyltk/table.py +++ b/pyltk/table.py @@ -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