1#Method 1:
2df["Delivery Charges"] = df[["Weight", "Package Size", "Delivery Mode"]].apply(
3 lambda x : calculate_rate(*x), axis=1)
4
5#Method 2:
6df["Delivery Charges"] = df.apply(
7 lambda x : calculate_rate(x["Weight"],
8 x["Package Size"], x["Delivery Mode"]), axis=1)
1In [49]: df
2Out[49]:
3 0 1
40 1.000000 0.000000
51 -0.494375 0.570994
62 1.000000 0.000000
73 1.876360 -0.229738
84 1.000000 0.000000
9
10In [50]: def f(x):
11 ....: return x[0] + x[1]
12 ....:
13
14In [51]: df.apply(f, axis=1) #passes a Series object, row-wise
15Out[51]:
160 1.000000
171 0.076619
182 1.000000
193 1.646622
204 1.000000
21