Answers for "how to apply a function on two columns in pandas"

2

pandas pass two columns to function

#Method 1:
df["Delivery Charges"] = df[["Weight", "Package Size", "Delivery Mode"]].apply(
  lambda x : calculate_rate(*x), axis=1)

#Method 2:
df["Delivery Charges"] = df.apply(
  lambda x : calculate_rate(x["Weight"], 
  x["Package Size"], x["Delivery Mode"]), axis=1)
Posted by: Guest on May-14-2021
1

python pandas apply function to one column

df['a'] = df['a'].apply(lambda x: x + 1)
Posted by: Guest on April-15-2020

Code answers related to "how to apply a function on two columns in pandas"

Python Answers by Framework

Browse Popular Code Answers by Language