Reputation: 1248
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?
Upvotes: 3
Views: 6359
Reputation: 294546
-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
Upvotes: 5