To solve Warning: invalid value encountered in double_scalars in Numpy error follow below methods.
ERROR LOG
Warning: invalid value encountered in double_scalars
Contents
How to solve Warning: invalid value encountered in double_scalars in Numpy ?
This issue is sometimes caused by NaN or null values in data when using Numpy. If you’re importing data from a CSV file or something similar and then using numpy arrays to manipulate it, the issue could have started with the data intake. You may pass a small collection of data with known values to your function and check if you get the same result.
Steps to fix Warning: invalid value encountered in double_scalars in Numpy ?
Arithmetic operations such as division and multiplication generate this mistake when NaN is not equal to NaN.
There are a few things you may take to avoid this issue:
- Use
pd.set_option
to set the number of decimals to consider in your analysis so that an infinite small number does not cause a similar difficulty. - Panda will ignore the leftover digits if you use
df.round()
to round the data. Furthermore, and most significantly, - Set NaN to zero by using
df=df.fillna(0)
. If Filling NaN with zero does not apply to your data sets, be aware that the record will be treated as zero, changing the N in the mean, std, and so on.
Hope the above solution works.
Also read :
TypeError: argument of type ‘int’ is not iterable
DatabaseError: current transaction is aborted commands ignored until end of transaction block