When you try to replace nan value with a custom numeric value using following code,
np.nan_to_num(exp_allowance,nan=9999.99)
it produces following error:
typeerror: nan_to_num() got an unexpected keyword argument 'nan'
In NumPy, to replace missing values NaN ( np. nan ) in ndarray with other numbers, use np. nan_to_num() or np. isnan() .
nan_to_num() function is used when we want to replace nan(Not A Number) with zero and inf with finite numbers in an array. It returns (positive) infinity with a very large number and negative infinity with a very small (or negative) number.
After going through several blogs and no answers to it, I discovered that I was using obsolete numpy version.This specific argument is only supported in numpy version 1.17 and above. Those who are facing this issue, check your numpy version:
import numpy
numpy.version.version
if it is below 1.17 then update it the latest using,
pip install numpy --upgrade
It will work.
The command to upgrade should be this:
pip install --upgrade numpy
The --upgrade argument comes before the module name. And if you are using it for a specific Python version, the code would be:
python37 -m pip install --upgrade numpy
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