Reputation: 832
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.
Upvotes: 2
Views: 1135
Reputation: 862641
Working with float
s, 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
Upvotes: 2