In [1]:
from pandas import DataFrame, Series

In [2]:
import pandas as pd

In [3]:
import numpy as np

In [4]:
frame = DataFrame(np.random.randn(4, 3), 
                  columns=list('bde'), index=['Utah', 'Ohio', 'Texas', 'Oregon'])

In [5]:
frame


Out[5]:
b d e
Utah 1.164044 -1.084572 2.658843
Ohio -1.491405 0.874359 -1.058734
Texas 0.378623 1.174664 -0.743128
Oregon 0.541705 0.196422 0.223049

In [6]:
np.abs(frame)


Out[6]:
b d e
Utah 1.164044 1.084572 2.658843
Ohio 1.491405 0.874359 1.058734
Texas 0.378623 1.174664 0.743128
Oregon 0.541705 0.196422 0.223049

In [7]:
f = lambda x: x.max() - x.min()

In [8]:
frame.apply(f)


Out[8]:
b    2.655449
d    2.259235
e    3.717577
dtype: float64

In [9]:
frame.apply(f, axis=1)


Out[9]:
Utah      3.743414
Ohio      2.365764
Texas     1.917791
Oregon    0.345283
dtype: float64

In [10]:
def f(x):
    return Series([x.min(), x.max()], index=['min', 'max'])

In [11]:
frame.apply(f)


Out[11]:
b d e
min -1.491405 -1.084572 -1.058734
max 1.164044 1.174664 2.658843

In [12]:
format = lambda x: '%.2f' % x

In [13]:
frame.applymap(format)


Out[13]:
b d e
Utah 1.16 -1.08 2.66
Ohio -1.49 0.87 -1.06
Texas 0.38 1.17 -0.74
Oregon 0.54 0.20 0.22

In [14]:
frame['e'].map(format)


Out[14]:
Utah       2.66
Ohio      -1.06
Texas     -0.74
Oregon     0.22
Name: e, dtype: object