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 Nov 11, 2014
1 parent 81c8a5f commit eb1536b
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 @@ -581,14 +581,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]

This comment has been minimized.

Copy link
@hayd

hayd Apr 17, 2015

I think you can use ljust here, i.e. [l.ljust(width) 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 eb1536b

Please sign in to comment.