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

Issue

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

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)

Answered By – QWERTYL

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *