Feb-09-2020, 05:49 PM
(This post was last modified: Feb-09-2020, 05:49 PM by new_to_python.)
Hi, I came across an example to replace sentinel values -999 by NaN. -999 is an integer. How come it can be used to replace those -999.0 elements in the Series?
import pandas as pd In [39]: data = pd.Series([1., -999., 2., -999., -1000., 3.]) In [40]: data Out[40]: 0 1.0 1 -999.0 2 2.0 3 -999.0 4 -1000.0 5 3.0 dtype: float64 In [41]: data.replace(-999, np.nan) Out[41]: 0 1.0 1 NaN 2 2.0 3 NaN 4 -1000.0 5 3.0 dtype: float64I did a test by typing:
-999 == -999.The interpreter gave True. Does the method "replace" automatically did type casting implicitely to convert decimal values to the nearest integer? I can't find this mentioned in
?pd.Series.replaceI have seen somewhere else that an integer (e.g. 3) is used interchangeably with its decimal counterpart (e.g. 3.). Why? integer 3 is not the same as 3.000000000000000000001. Is there a rule here?