Reputation: 549
Suppose I have a function with N parameters and Dataframe df
with N columns.
def func(param1, param2, ... paramN)
I want to pass each columns as parameters.
func(df[0], df[1], ... df[N-1])
How to code it in a simple way if N is large.
Upvotes: 0
Views: 38
Reputation: 2518
*
operator to do itdef func(a,b,c):
print(a,b,c)
func(*[1,2,3])
1 2 3
Upvotes: 1
Reputation: 2758
Try this:
def func(*args):
param1 = args[0]
...
df = [1,2,3]
func(*df)
With *args
you can pass a variable number of positional arguments.
Upvotes: 1