pandas 0.7.0 documentation

pandas.DataFrame.apply

DataFrame.apply(func, axis=0, broadcast=False, raw=False, args=(), **kwds)

Applies function along input axis of DataFrame. Objects passed to functions are Series objects having index either the DataFrame’s index (axis=0) or the columns (axis=1). Returns either a DataFrame (if the function produces another Series) or a Series indexed on either the index or columns if the function produces an aggregated value.

Parameters :

func : function

Function to apply to each column

axis : {0, 1}

broadcast : bool, default False

For aggregation functions, return object of same size with values propagated

raw : boolean, default False

If False, convert each row or column into a Series. If raw=True the passed function will receive ndarray objects instead. If you are just applying a NumPy reduction function this will achieve much better performance

args : tuple

Positional arguments to pass to function in addition to the array/series

Additional keyword arguments will be passed as keywords to the function :

Returns :

applied : Series or DataFrame

Notes

Function passed should not have side effects. If the result is a Series, it should have the same index

Examples

>>> df.apply(numpy.sqrt) # returns DataFrame
>>> df.apply(numpy.sum, axis=0) # equiv to df.sum(0)
>>> df.apply(numpy.sum, axis=1) # equiv to df.sum(1)