0

I got the result and then try to retrieve the values I got None values

I have defined a function who_score('d','g','sm',a,ch,sb) and then I want to use that function to make a new list based on if conditions. So, I made a loop to iterate over my data df_6_factors and append the result for each row in a new list called who_estimator

here is my code:

who_esimator = []     #the empty list
for i in range(10):
if df_6_factors.isnull().iat[i,0]  or df_6_factors.isnull().iat[i,1] or df_6_factors.isnull().iat[i,2] or df_6_factors.isnull().iat[i,3] or df_6_factors.isnull().iat[i,4] or df_6_factors.isnull().iat[i,5]:
    who_esimator.append('NaN')
else:
    if df_6_factors.iat[i,1] == 0:
        d = 'n'
    elif df_6_factors.iat[i,1] == 1:
        d = 'y'
    else:
        d = 'e'
    if df_6_factors.iat[i,2] == 0:
        g = 'm'
    elif df_6_factors.iat[i,2] == 1:
        g = 'f'
    else:
        g = 'e'
    a = df_6_factors.iat[i,3]
    if df_6_factors.iat[i,4] <=2:
        sm = 'n'
    else:
        sm = 'y'
    ch = df_6_factors.iat[i,5]
    sb = df_6_factors.iat[i,6]
    who_esimator.append(who_score(d,g,sm,a,ch,sb))

I got the output that I want as you see here:

15
2
6
4
7
40
20
6

but when I want to read the list who_esimator I got none value and 'NaN' value even though the data is not Null

[None, 'NaN', None, None, None, None, 'NaN', None, None, None]

I am a python self_learner and appreciate any help

Thanks

talnazzal
  • 21
  • 1
  • 2
    Looks like you forgot to include the code for `who_score`; without seeing that code it's literally impossible to solve this for you. – Random Davis Aug 18 '22 at 21:38
  • 1
    It sounds like `who_score()` is printing its result instead of returning it. – Barmar Aug 18 '22 at 21:39
  • @Barmar I was actually writing that as an answer, but I'll wait for the function code (because in some cases it's returning NaN instead) – user19513069 Aug 18 '22 at 21:40
  • 1
    @user19513069 No answer is needed if that's the problem. I preemptively closed it as a duplicate. The `NaN` is coming from `who_esimator.append('NaN')` in the `if` statement at the top. – Barmar Aug 18 '22 at 21:41

0 Answers0