def truncate(f, n):
    """Truncates/pads a float f to n decimal places without rounding"""
s = '{}'.format(f)
if 'e' in s or 'E' in s:
    return '{0:.{1}f}'.format(f, n)
i, p, d = s.partition('.')
return '.'.join([i, (d + '0' * n)[:n]])
dfu['closeScaled'] = dfu.close.div(dfu.groupby(level=0)['open'].transform(
    'first'))
Pandas - How to scale a column in a multi-index dataframe to the top row in each level=0 group