Python Forum
Why replace treats an integer value 999 as 999.0?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why replace treats an integer value 999 as 999.0?
#1
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: float64
I 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.replace 
I 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?
Reply


Messages In This Thread
Why replace treats an integer value 999 as 999.0? - by new_to_python - Feb-09-2020, 05:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search & Replace - Newlines Added After Replace dj99 3 3,405 Jul-22-2018, 01:42 PM
Last Post: buran
  Using a variable to replace an integer? (Except it isn't working!) s1monsays 15 8,389 Jul-25-2017, 06:58 PM
Last Post: s1monsays

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020