2

I have a pandas dataframe which consists of 3000 latitude longitude values. I want to check if a lat-long exists in the dataframe or not.

The data frame looks like the following:

lat      long
31.76    77.84
31.77    77.84
31.78    77.84
32.76    77.85

Now, I want to check if (31.76, 77.84) exists or not in the above dataframe. If yes, then the index also.

lsr729
  • 752
  • 2
  • 11
  • 25

1 Answers1

2

Working with floats, so need numpy.isclose for check both columns, chain with & for bitwise AND and test with any for at least one True of boolean mask:

tup = (31.76, 77.84)
lat, long = tup

a = (np.isclose(df['lat'], lat) & np.isclose(df['long'], long)).any()
print (a)
True
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252