Skip to content

Commit

Permalink
Issue with to_latex and MultiIndex column format
Browse files Browse the repository at this point in the history
This is a potential resolution to
pandas-dev#8336
It borrows the same code flow from _get_formatted_index in
pandas.core.format
  • Loading branch information
kotfic committed Mar 26, 2015
1 parent 8d2818e commit 64c3921
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,20 @@ def get_col_type(dtype):
strcols = self._to_str_columns()

if self.index and isinstance(self.frame.index, MultiIndex):
clevels = self.frame.columns.nlevels
strcols.pop(0)
name = any(self.frame.columns.names)
for i, lev in enumerate(self.frame.index.levels):
lev2 = lev.format(name=name)
width = len(lev2[0])
lev3 = [' ' * width] * clevels + lev2
strcols.insert(i, lev3)


fmt = self._get_formatter('__index__')
fmt_index = self.frame.index.format(sparsify=self.sparsify,
adjoin=False,
names=False,
formatter=fmt)

for i, lev in enumerate(fmt_index):
width = len(lev[0])
lev2 = [width * ' ' if l == '' else l for l in lev]
lev2.insert(0, width * ' ')
strcols.insert(i, lev2)

if column_format is None:
dtypes = self.frame.dtypes.values
Expand Down

0 comments on commit 64c3921

Please sign in to comment.