Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame({'angles': [0, 3, 4],
                   'degrees': [360, 180, 360]},
                  index=['ellipse', 'right triangle', 'rhombus'])
df
Out[2]:
angles degrees
ellipse 0 360
right triangle 3 180
rhombus 4 360
In [3]:
df.mod
Out[3]:
<bound method _arith_method_FRAME.<locals>.f of                 angles  degrees
ellipse              0      360
right triangle       3      180
rhombus              4      360>
In [4]:
df_multindex = pd.DataFrame({'angles': [0, 3, 4, 5, 6],
                             'degrees': [360, 180, 360, 540, 720]},
                            index=[['X', 'X', 'X', 'Y', 'Y'],
                                   ['ellipse', 'right triangle', 'rhombus',
                                    'pentagon', 'hexagon']])
df_multindex
Out[4]:
angles degrees
X ellipse 0 360
right triangle 3 180
rhombus 4 360
Y pentagon 5 540
hexagon 6 720
In [5]:
df.mod(df_multindex, level=1, fill_value=0)
Out[5]:
angles degrees
X ellipse NaN 0.0
right triangle 0.0 0.0
rhombus 0.0 0.0
Y pentagon 0.0 0.0
hexagon 0.0 0.0