Skip to content
Advertisement

How to write a function to find clients that are gone, boomeranging, new, etc?

I am trying to come up with a dynamic way to check for the existence of a string and report back a few different results: gone_client, boomerang, new_client.

  1. If I groupby address_id and my_date, and the pattern is Verizon, Verizon, Comcast, Comcast, the client left Verizon and went to another company.

  2. If the client went from Verizon to Comcast and then back to Verizon, this is a boomerang.

  3. If the client is new to Verizon last month, this is a new client, but if the client was with Verizon at some point in the past and new last month, this is a boomerang.

    import pandas as pd import numpy as np

    JavaScript

I can’t get the logic quite right, but I think it’s something along these lines…but something seems to be off.

JavaScript

Maybe something like this…

JavaScript

I’m not sure how to handle the dates though, and only by checking the dates can you know whether a client is gone, boomeranging, new, or maybe some weird patterns which doesn’t fit into a bucket, like ‘Other’. Expected result would be this (last scenario is kind of a boomerang that left yet again). I wouldn’t expect many scenarios like this, but there certainly will be some very unique cases, so ‘Other’ is fine for these records.

JavaScript

Advertisement

Answer

Here’s a solution with some verbose logic that you can play around with. It doesn’t sound like you’re quite certain of your final logic but hopefully this gives you enough to play around with.

This solution groups the dataframe based on the address_id. Then, for each individual group, we can examine which my_company feature. We can use this, along with a timedelta to have some logic around whether the address is with Verizon, not with Verizon, never with Verizon, is currently with Verizon and came back in the last 30 days, etc.

This answer is not sponsored by Verizon. Other cellular providers exist.


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