Slicing or aggregating data frame based on certain conditions
<p>I have a dataset which contains latitude and longitudes. I want to take those rows in data set where distance is less than 1 km. For entire distance calculation part I have written a function which will return true or false. So I want to consider those rows on which this condition is applied.</p>

<p>It may be through lambda function but not sure how as I think lambda always return a value might be.
If conditions can be applied for column values but think that is not enough in my case.</p>

<p>Any leads are appreciated.
TIA.</p>

<p>Can you give more information about your dataset? Does he contain two columns, one for lat and one for long?</p>

<p>If you want to apply your func to the dataset you can use <code>map</code>
Somth like this:</p>

<pre><code>func = lambda x: x &gt; 0
data = [1, -1, 3, -2]
result = list(map(func, dataset))
</code></pre>

<p>After that you will get:</p>

<pre><code>result = [True, False, True, False]
</code></pre>

<p>Or you can vectorize your processing with use of <code>numpy</code></p>

<pre><code>import numpy as np

func = np.vectorize(lambda x: x &gt; 0)
data = np.array([1, -1, 3, -2])
result = func(data)
</code></pre>

<p>It will fastest one solution.</p>

<p>If u give more information about structure of dataset i will try to fix your problem</p>

python python-3.x lambda aggregate