Skip to content
Advertisement

How to compare each date in a cell with all the dates in a column

I have a dataframe with three columns lets say

JavaScript

I want to compare each date in Date column with all the other dates in the Date column and only keep those rows which lie within 6 months of atleast one of all the dates.

JavaScript

Desired Output:

JavaScript

I have tried a couple of approches such a nested loops, but I got 1 million+ entries and it takes forever to run that loop. Some of the dates repeat too. Not all are unique.

JavaScript

I need a much more omptimal solution for it. Studied about lamba functions, but couldn’t get to the depths of it.

Advertisement

Answer

IIUC, this should work for you:

JavaScript

Output:

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