0

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)
Kel Varnsen
  • 314
  • 2
  • 8
  • 1
    This is a really good question to ask for a beginner and the answers in the duplicate link explain it thoroughly. Good luck learning pandas – Erfan Jun 21 '20 at 18:26
  • That was perfect, thank you! I had trouble finding a question like that. – Kel Varnsen Jun 21 '20 at 18:29

0 Answers0