bpd.Series.apply

Series.apply(func)[source]

Invoke function on values of Series.

Can be ufunc (a NumPy function that applies to the entire Series) or a Python function that only works on single values.

Parameters:func (function) – Python function or NumPy ufunc to apply.
Returns:a_obj – If func returns a Series object the result will be a DataFrame.
Return type:Series or DataFrame

Examples

>>> def cut_off_5(val):
...     if val > 5:
...         return 5
...     else:
...         return val
>>> s = bpd.Series(data=[1, 3, 5, 7, 9]
>>> s.apply(cut_off_5)
0    1
1    3
2    5
3    5
4    5
dtype: int64