Reputation: 81
All
I have two columns and I divide one by the other with colb being my denominator. When I divide one by the other however I get infs when there is 0 present in my colb e.g
df[cola]/df[colb]
Mathematically this is correct right? Just wondering if this is expected with pandas . Fir me it makes no sense to have these infs so I will probably replace with 0 but wanted to check
Upvotes: 2
Views: 377
Reputation: 11504
For x≠0 , and x∈R , the limits of x/0 as we approach from the left and right hand sides of 0 differ. Hence, it's not defined.
Consider approaching the limit from the right hand side. As the denominator gets smaller and smaller, the value will approach ±∞ depending upon the sign of x . If x>0 , the limit will approach ∞ and if x<0 , the limit approaches −∞ .
If we approach the limit from the left, if x>0 , the limit approaches −∞ and similarly ∞ when x<0 .
In both cases, there is a discontinuity when the denominator approaches 0 and hence x/0 is undefined.
Hence, even in pandas this should yield. However, it is a convention that x/0
is inf
if x>0
, -inf
if x<0
Upvotes: 2