-
-
Save gbushnell/78c9ee60369f0788bc80ae782469a43d to your computer and use it in GitHub Desktop.
RFM Helper Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get days since last invoice (Recency) | |
def get_history(x): | |
d = data[data['client_id'] == x.client_id] | |
d_max = max(d['invoice_date']) | |
t = datetime.today() | |
y = t - d_max | |
return y.days | |
#count number of invoices for client (Frequency) | |
c_invoices_dict = collections.Counter(data['client_description']) | |
def get_counts(x): | |
return c_invoices_dict[x.client_description] | |
#get total amount of all invoices for client (Monetary Value) | |
def total_invoices(x): | |
d = data[data['client_description'] == x.client_description] | |
total = d.amount.sum() | |
return total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment