Skip to content
Advertisement

How to find lines in pandas columns with close values?

I need to find ‘user_id’ of users standing closeby to each other. So we have data:

JavaScript
JavaScript

So, in this dataset it would be users with id ‘101’ and ‘302’. But our dataset has millions of lines in it. Are there any built-in functions in pandas or python to solve the issue?

Advertisement

Answer

Assuming the workers need to share the same location to be considered standing closeby, a groupby by location can match workers efficiently:

JavaScript

Which outputs:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement