Apologies if this has been asked before but I couldn't find this exact question answered. I want to take the values in 2 Pandas Data Frame columns, divide them, and store it in a new column in the df for all rows.
My Question is:
Is it more efficient/better practice to use the apply
lambda function on a Pandas Data Frame in Python or to do the column operations "directly"? Or if there's another more accepted practice that would be appreciated as well.
"Directly":
df["Ratio"] = df["x"] / df["y"]
Versus with apply
lambda:
df["Ratio"] = df.apply(lambda row: row.x / row.y, axis=1)