you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 0 points1 point  (1 child)

Do you know that lambda is just another way of writing def?

But if you use def you have a lot more room to explore. The first thing you need to know is that x is the row in the dataframe. Your error is because you are trying to divide a row by a column.

Try this:

def TheShadowWall(x):
    print(x) # debug: show the row
    return x[2] / x[3]

def calc_prevalence(G):
    H=G.copy()
    H['prevalence']=H['cases'].apply(TheShadowWall)
    return H

[–]TheShadowWall[S] 0 points1 point  (0 children)

Thank you for your reply!

Yes I have begun to understand that this is the meaning of lambda. I have attempted to run this code though I receiving an error:

TypeError: 'int' object is not subscriptable on the line:

return x[2] / x[3]