Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (18.4k points)
edited by

I am new to python, I want to sum the certain scores and when I type the code normally, it works perfectly:

select_df = df.filter(like = 'ABC')

select_df = select_df.loc[(df.REF == '000')]


but when I define a function and try it like this, it is not working:

def sum_score(a, b):

    select_df = df.filter(like = a)

    select_df = select_df.loc[(df.REF == b)]


sum_score('ABC', '000')

And when I type it as:

print(sum_score('ABC', '000'))

The output says NONE

1 Answer

0 votes
by (36.8k points)

You have to return your df from the function:

def sum_score(qu, vc):

    select_df = df.filter(like = qu)

    select_df = select_df.loc[(df.REF == vc)]


    return select_df # Return the df

Then call the function like this:

print(sum_score('ABC', 'V000'))

Improve your knowledge in data science from scratch using Data science online courses 

Browse Categories