I am sorry for asking such a trivial question, but I keep making mistakes when using the apply function with a lambda function that has input parameters.
See below:
df = pd.DataFrame([["John",1,3],["James",2,3],
["Femi",3,4], ["Rita",3,3],
["Rita",3,3]], columns=["Name","Age","Height"])
%timeit df["product_AH"] = df[["Age", "Height"]].apply(lambda x,y: x['Age']*y['Height'], axis=1)
Expected output:
Name Age Height product_AH
0 John 1 3 3
1 James 2 3 6
2 Femi 3 4 12
3 Rita 3 3 9
4 Rita 3 3 9
df[["Age", "Height"]].apply(lambda x: x['Age']*x['Height'], axis=1), you dont need 2 args here , though you dont need apply at all , pandas is vectorized to do thisdf['Age'] * df['Hieght']