Search code examples
pythonpandasdataframepandas-apply

pd.Series.apply keyword arguments are are a pd.series


I am using apply on a series in a dataframe to use a function with multiple keyword arguments. I am using the apply function on the first input (called sk), then the other arguments I have in other columns of my dataframe. My apply line looks like this:

Updates['Action'] = Updates['sk'].apply(RCCheck.nsamcheck, reportseries=Updates['reportseries'],rssd=Updates['rssd'], username=username, pw=password)

I get an the error (the function is querying an Oracle SQL database):

DatabaseError: ORA-12801: error signaled in parallel query server P000
ORA-01722: invalid number

However, if I use:

 Updates['Action'] = Updates['sk'].apply(RCCheck.nsamcheck, reportseries='abcd',rssd='1234', username=username, pw=password)

It works no problem, but the point of using the pd.series references is so that it could move down each row and return he function output. Report series and rssd vary per row. I can't really share more of the code so I apologize for not sharing a whole lot.

Is what I'm trying to do possible?


Solution

  • Instead of applying the function to a series, apply it to the whole dataframe.

    def my_new_func(row):
        return RCCheck.nsamcheck(
            reportseries=row['reportseries'], rssd=row['rssd'], username=username, pw=password
    )
    
    Updates['Action'] = Updates.apply(my_new_func, axis=1)