how to apply function to multiple columns pandas code example
Example 1: pandas pass two columns to function
df["Delivery Charges"] = df[["Weight", "Package Size", "Delivery Mode"]].apply(
lambda x : calculate_rate(*x), axis=1)
df["Delivery Charges"] = df.apply(
lambda x : calculate_rate(x["Weight"],
x["Package Size"], x["Delivery Mode"]), axis=1)
Example 2: assign multiple columns pandas
import pandas as pd
df = {'col_1': [0, 1, 2, 3],
'col_2': [4, 5, 6, 7]}
df = pd.DataFrame(df)
df[[ 'column_new_1', 'column_new_2','column_new_3']] = [np.nan, 'dogs',3]