Examples

In [2]:
import numpy as np
import pandas as pd
In [3]:
df = pd.DataFrame({'angles': [0, 3, 4],
                   'degrees': [360, 180, 360]},
                  index=['ellipse', 'triangle', 'rhombus'])
df
Out[3]:
angles degrees
ellipse 0 360
triangle 3 180
rhombus 4 360

Divide by constant with reverse version.

In [4]:
df.div(10)
Out[4]:
angles degrees
ellipse 0.0 36.0
triangle 0.3 18.0
rhombus 0.4 36.0

Add a scalar with operator version which return the same results.

In [5]:
df.rdiv(10)
Out[5]:
angles degrees
ellipse inf 0.027778
triangle 3.333333 0.055556
rhombus 2.500000 0.027778

Divide by a MultiIndex by level.

In [6]:
df_multindex = pd.DataFrame({'angles': [0, 3, 4, 4, 5, 6],
                             'degrees': [360, 180, 360, 360, 540, 720]},
                            index=[['X', 'X', 'X', 'Y', 'Y', 'Y'],
                                   ['ellipse', 'triangle', 'rhombus',
                                    'rectangle', 'pentagon', 'hexagon']])
df_multindex
Out[6]:
angles degrees
X ellipse 0 360
triangle 3 180
rhombus 4 360
Y rectangle 4 360
pentagon 5 540
hexagon 6 720
In [7]:
df.div(df_multindex, level=1, fill_value=0)
Out[7]:
angles degrees
X ellipse NaN 1.0
triangle 1.0 1.0
rhombus 1.0 1.0
Y rectangle 0.0 0.0
pentagon 0.0 0.0
hexagon 0.0 0.0