'I have inf values in a dataset column that don't see like inf at all

I have this operation:

df['netPCR'] = df['ValorNeto'] / df.index.map(PCR['ValorNeto'])

df['netPCR'] = df['netPCR'].fillna(0)

But some how when

df['netPCR'].sum()

It results in inf and when I try to get what values are inf things just get weird.

enter image description here

What do you think it is happening and how to fix it?

I tried to round values or convert them to objects, but the problem is not fixed.



Solution 1:[1]

It seems like division by 0 is returning infinity and not nan. You can use df.replace:

df.replace([np.inf, -np.inf], 0, inplace=True)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 QWERTYL