-1

I am trying to call a function but with no success the target is to run rules for examination of segregation of duties

per=pd.read_excel('Permissionwp.xlsx',sheet_name='Sheet1')
def take_first(elem):
        return elem[0]
def sod(permissiona,permissionb):
        rsod=[]
        ls1=[]
        ls2=[]

    for i in  range(len(per)):
        if per.iloc[i,5]==permissiona:
            ls1.append((per.iloc[i,1],per.iloc[i,4]))

        else:
            pass

    for i in  range(len(per)):
        if per.iloc[i,5]==permissionb:
            ls2.append((per.iloc[i,1],per.iloc[i,4]))

        else:
            pass
    for user in ls1:
        if user in ls2:
             rsod.append(user)
             rsod=list(set(rsod))   

    for i in sorted(rsod,key=take_first):
        print(i)

the problem is below- I am trying to call to sod function by running rules file using the sod is not bringing me the result rather "None"

l=()
count=0
risk=pd.read_excel('risk.xlsx',sheet_name='Sheet1')
for num in range(len(risk)):

    sod(risk.iloc[num,4],risk.iloc[num,5])   

here is the problem

zachi
  • 511
  • 4
  • 13
  • 3
    Does this answer your question? [Python: My function returns "None" after it does what I want it to](https://stackoverflow.com/questions/19105961/python-my-function-returns-none-after-it-does-what-i-want-it-to) – Tomerikoo Mar 04 '20 at 20:34
  • As an aside, what is the point of the `else: pass` ? – AMC Mar 04 '20 at 20:48
  • Does this answer your question? [Python Script returns unintended "None" after execution of a function](https://stackoverflow.com/questions/16974901/python-script-returns-unintended-none-after-execution-of-a-function) – Brydenr Mar 04 '20 at 21:56

1 Answers1

0

As for the question: are you positive that the last conditions in your rsod function and that the rsod list is not empty? Plus, by bringing "None" did you mean that the printed output is "None"?

A remarks about the code: It seems that the per object type is DataFrame so using all these for loops is probably very not effective. You should instead apply vectorization commands directly on your DataFrame, turning each for loop into a one liner.

You can read about different ways to loop a DataFrame here: https://towardsdatascience.com/how-to-make-your-pandas-loop-71-803-times-faster-805030df4f06

DvirH
  • 70
  • 8