You could zip with individual columns of the multi-column DataFrame:
import pandas as pd
df1 = pd.DataFrame({"col_1": [1, 2, 3]})
df2 = pd.DataFrame({"col_1": [4, 5, 6]})
df3 = pd.DataFrame({"col_1": [7, 8, 9], "col_2": [10, 11, 12]})
def f(w, x, y, z):
return sum([w, x, y, z])
result = [
f(w, x, y, z)
for w, x, y, z
in zip(
df1["col_1"], df2["col_1"],
df3["col_1"], df3["col_2"] # list all required df3 columns individually
)
]
print(result)
Output:
[22, 26, 30]
Or you could join the DataFrames into a single one first:
df = df1.join(df2, lsuffix="_df1").join(df3, lsuffix="_df2")
print(df)
result = [
f(w, x, y, z)
for idx, (w, x, y, z)
in df.iterrows()
]
print(result)
Output:
col_1_df1 col_1_df2 col_1 col_2
0 1 4 7 10
1 2 5 8 11
2 3 6 9 12
[22, 26, 30]
Or you could convert df3 to a list of Series and "pivot" it using zip like below.
def f(x, y, z):
return x, y, z
result = [
f(x, y, z)
for x, y, z
in zip(
df1["col_1"],
df2["col_1"],
zip(*[df3[c] for c in df3.columns]))
]
print(result)
Output:
[(1, 4, (7, 10)), (2, 5, (8, 11)), (3, 6, (9, 12))]