First page Back Continue Last page Overview Graphics

Example for apply

Doesn't make a lot of sense, but anway:

>>> import pandas as pd

>>> import numpy as np

>>> fruits = ['peaches', 'oranges', 'cherries', 'pears']

>>> S = pd.Series([20, 33, 52, 10], index=fruits)

>>> S.apply(np.sin)

peaches 0.912945

oranges 0.999912

cherries 0.986628

pears -0.544021

dtype: float64

Let's increase the quantities of fruits which are less than 50 by 10:

>>> S.apply(lambda x: x if x > 50 else x+10 )

peaches 30

oranges 43

cherries 52

pears 20

dtype: int64