I have a Data frame like this,
a b c d e
1 0 0 4 5
0 23 5 0 0
0 5 8 6 0
Now, i am using a np.log on the entire data frame like this.
df = (np.log(weights_df))
Its all fine and working out. But wherever there is 0, its giving "-inf" as it is supposed to. I want to convert all of these to something else, maybe "0" in place of "-inf". I tried fillna but i do not think its going to work here.
How do i do it?
-np.inf and np.inf are not considered null or na.
Use replace(-np.inf, 0):
df = (np.log(weights_df)).replace(-np.inf, 0)
df

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With