API: cut interval formatting · Issue #8595 · pandas-dev/pandas (original) (raw)
it would be nice to have number in front of all labels. put number like 00, 01, 02 in front of labels so that it would order appropriately.
def _format_levels(bins, prec, right=True,
include_lowest=False):
fmt = lambda v: _format_label(v, precision=prec)
cnter=0
if right:
levels = []
for a, b in zip(bins, bins[1:]):
fa, fb = fmt(a), fmt(b)
if a != b and fa == fb:
raise ValueError('precision too low')
formatted = '%02d: (%s, %s]' % (cnter, fa, fb)
cnter=cnter +1
levels.append(formatted)
if include_lowest:
levels[0] = '[' + levels[0][1:]
else:
levels = ['[%s, %s)' % (fmt(a), fmt(b))
for a, b in zip(bins, bins[1:])]
return levels