i would like to use the following function to filter a dataframa
def isInRadius(position):
latCheck = False
lonCheck = False
if position.lat < 0:
latCheck = position.lat <= upperLat and position.lat >= lowerLat
else:
latCheck = position.lat >= upperLat and position.lat <= lowerLat
if not latCheck:
return False
if position.lon < 0:
lonCheck = position.lon <= righterLon and position.lon >= lefterLon
else:
lonCheck = position.lon >= righterLon and position.lat <= lefterLon
return latCheck and lonCheck
The dataframe has more columns than 'lat' and 'lon' but i would like to filter it by those 2 according to the logic implemented on the function above.
I have try dataFrame.filter(lambda x: isInRadius(x)) and dataFrame.filter(isInRadius) and dataFrame.filter(lambda x: isInRadius(x.iLoc[0])) and other approaches but none worked, resulting in the error "TypeError: 'function' object is not iterable"
How should i do it?
On C# i would do
var filtered = myCollection.Where(x => isInRadius(x));
lowerLat,upperLat, etc? Can you explain the logic ofisInRadius?filterworks on index, so it should not work regardless of what syntax you use since the filtering you want is done over the values and not the indexes.loc.df[df.apply(lambda x: isInRadius(x), 1)]