yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #25219
Re: [Question #693071]: ValueError: cannot convert float NaN to integer
Question #693071 on Yade changed:
https://answers.launchpad.net/yade/+question/693071
haviernick proposed the following answer:
You can avoid this with a mask method. Note first that in python NaN is
defined as the number which is not equal to itself:
>float('nan') == float('nan')
False
It might be worth avoiding use of np.NaN altogether. NaN literally means
"not a number", and it cannot be converted to an integer. In general,
Python prefers raising an exception to returning NaN, so things like
sqrt(-1) and log(0.0) will generally raise instead of returning NaN.
However, you may get this value back from some other library. From
v0.24, you actually can. Pandas introduces Nullable Integer Data Types
which allows integers to coexist with NaNs. Also, even at the lastest
versions of pandas if the column is object type you would have to
convert into float first, something like:
df['column_name'].astype(np.float).astype("Int32")
NB: You have to go through numpy float first and then to nullable Int32,
for some reason.
http://net-informations.com/ds/pd/default.htm
--
You received this question notification because your team yade-users is
an answer contact for Yade.