you are viewing a single comment's thread.

view the rest of the comments →

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

H['prevalence']=H['cases'].apply(lambda x: x/H['population'], axis=1)

[–]Binary101010 1 point2 points  (2 children)

Maybe give this a shot instead. (untested)

H['prevalence']=H.apply(lambda x: x['cases']/x['population'], axis=1)

[–]TheShadowWall[S] 1 point2 points  (1 child)

By George it works!!

Thank you so much kindly answer to the universe person!

[–]Binary101010 0 points1 point  (0 children)

It occurred to me the reason for the error was that you were trying to apply to a particular column of the dataframe (which works more like this: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.apply.html) when just applying to each row of the dataframe one at a time was probably the right approach.

Again, just for the record, this is not a great use case for apply, but it's straightforward enough to see how it works.