Skip to content
Advertisement

cannot search value in dataframe althought the value exists

I have a data frame with location data. I know a value for a certain location exists and I even know its index location. When I search using index location the values is shown correctly but if I search using a combination of other columns(lat and lon), the value does not show. I am attaching the screenshot below. enter image description here

Here I know lat 31.92 and lon 76.66 are at index 2656536. When I subset using lat and lon, the result is empty. The result should have been as shown in the figure.

PS this is only happening only for some values(10%) not all

Advertisement

Answer

Problem is with precision of floats, so we need to use numpy.isclose:

df[(np.isclose(df.lat, 31.92)) & (np.isclose(df.lon, 76.66))]
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement