简体   繁体   中英

To run a python function with multiple parameters

I have a function here:

def ROC(dfH, n):  
    M = dfH['Close'].diff(n - 1)  
    N = dfH['Close'].shift(n - 1)  
    ROC = pd.Series(M / N, name = 'ROC_' + str(n))  
    dfH = dfH.join(ROC)  
    return dfH

With the above function I want to make multiple columns by changing the value of n so i run the code

a = (4, 8)
for j in a:
    ROC(dfH, n=a)

which gets to be wrong. please help thanks in advance.

`

a = (4, 8)
for j in a:
    ROC(dfH, n=a)
               ^

You are using a instead of j in the for loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM