The function np.where just chooses elements from two arrays that are both
computed before np.where is even executed. See this StackOverflow answer
https://stackoverflow.com/a/29950752/4681187 if you want to suppress the
error.

On Thu, Apr 25, 2024 at 8:16 PM 840362492--- via NumPy-Discussion <
numpy-discussion@python.org> wrote:

> 0
>
> In my code, I use the following calculation for a column in the dataframe:
> np.where(df_score['number'] ! = 0, 100 - ((100 * df_score[rank_column]
> -50)/df_score['number']), None),I have used df_score['number']! = 0, but
> the code is still wrong, ZeroDivisionError: float division by zero, even if
> I put df_score['number']! = 0 changed to df_score['number'] > 0, why?
>
> pandas version:1.1.5 numpy version:1.24.4
>
> Here are my numbers: 12.00000 12.00000 12.00000 12.00000 12.00000 0.00000
> 0.00000 0.00000 0.00000 0.00000 12.00000 12.00000 12.00000
>
> I want to know why it went wrong and what should be done to fix it? Thank
> you for your help
> _______________________________________________
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: fan...@umich.edu
>
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to