Is possible to pass a DataFrame to an apply
function like this?
df2 = df1.apply(func,axis=1,args=df2)
def func(df1,df2):
# do stuff in df2 for each row of df1
return df2
The two DataFrames do not have the same length.
Is possible to pass a DataFrame to an apply
function like this?
df2 = df1.apply(func,axis=1,args=df2)
def func(df1,df2):
# do stuff in df2 for each row of df1
return df2
The two DataFrames do not have the same length.
From the df.apply
docs:
DataFrame.apply(func, axis=0, broadcast=False, raw=False, reduce=None, args=(), **kwds)
Applies function along input axis of DataFrame.
args
:tuple
Positional arguments to pass to function in addition to the array/series.
The right way is to pass your arguments in a tuple, like this:
df1.apply(func, axis=1, args=(df2, ))
Further improvements to your code would be possible if it were known what you are trying to achieve.