{"action":"created","comment":{"url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/comments/26542615","id":26542615,"diff_hunk":"@@ -114,6 +115,32 @@ def to_period(d):\n     return customers[['frequency', 'recency', 'T']].astype(float)\n \n \n+def calculate_alive_path(model, transactions, datetime_col, units, freq='D'):\n+    \"\"\"\n+    :param model: A fitted lifetimes model\n+    :param transactions: a Pandas DataFrame containing the transactions history of the customer_id\n+    :param datetime_col: the column in the transactions that denotes the datetime the purchase was made\n+    :param units: the number of time units since the birth we want to draw the p_alive\n+    :param freq: Default 'D' for days. Other examples= 'W' for weekly\n+    :return: A pandas Series containing the p_alive as a function of T (age of the customer)\n+    \"\"\"\n+    _df = pd.DataFrame(transactions[datetime_col].copy())\n+    _df.index = _df[datetime_col]\n+    # Add transactions column\n+    _df['transactions'] = 1\n+    purchase_history = _df.resample(freq, how='sum').reset_index().fillna(0).drop([datetime_col], axis=1)['transactions'].values\n+    extra_columns = units - len(purchase_history)\n+    _df = pd.DataFrame(np.append(purchase_history, [0] * extra_columns), columns=['transactions'])\n+    # add T column\n+    _df['T'] = _df.index.values","path":"lifetimes/utils.py","position":31,"original_position":31,"commit_id":"ca0ed0ad0fc1e09521ee68d3ee3240c98cd23077","original_commit_id":"ca0ed0ad0fc1e09521ee68d3ee3240c98cd23077","user":{"login":"CamDavidsonPilon","id":884032,"avatar_url":"https://avatars.githubusercontent.com/u/884032?v=3","gravatar_id":"","url":"https://api.github.com/users/CamDavidsonPilon","html_url":"https://github.com/CamDavidsonPilon","followers_url":"https://api.github.com/users/CamDavidsonPilon/followers","following_url":"https://api.github.com/users/CamDavidsonPilon/following{/other_user}","gists_url":"https://api.github.com/users/CamDavidsonPilon/gists{/gist_id}","starred_url":"https://api.github.com/users/CamDavidsonPilon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CamDavidsonPilon/subscriptions","organizations_url":"https://api.github.com/users/CamDavidsonPilon/orgs","repos_url":"https://api.github.com/users/CamDavidsonPilon/repos","events_url":"https://api.github.com/users/CamDavidsonPilon/events{/privacy}","received_events_url":"https://api.github.com/users/CamDavidsonPilon/received_events","type":"User","site_admin":false},"body":"`_df['T'] = np.arange(df.shape[0])`. The fact that `index.values` is the same is a coincidence","created_at":"2015-03-17T01:09:49Z","updated_at":"2015-03-17T01:09:49Z","html_url":"https://github.com/CamDavidsonPilon/lifetimes/pull/9#discussion_r26542615","pull_request_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/comments/26542615"},"html":{"href":"https://github.com/CamDavidsonPilon/lifetimes/pull/9#discussion_r26542615"},"pull_request":{"href":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/9","id":31263518,"html_url":"https://github.com/CamDavidsonPilon/lifetimes/pull/9","diff_url":"https://github.com/CamDavidsonPilon/lifetimes/pull/9.diff","patch_url":"https://github.com/CamDavidsonPilon/lifetimes/pull/9.patch","issue_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/issues/9","number":9,"state":"open","locked":false,"title":"Added calculate_alive_path function + graphs + test","user":{"login":"erikvdp","id":203481,"avatar_url":"https://avatars.githubusercontent.com/u/203481?v=3","gravatar_id":"","url":"https://api.github.com/users/erikvdp","html_url":"https://github.com/erikvdp","followers_url":"https://api.github.com/users/erikvdp/followers","following_url":"https://api.github.com/users/erikvdp/following{/other_user}","gists_url":"https://api.github.com/users/erikvdp/gists{/gist_id}","starred_url":"https://api.github.com/users/erikvdp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikvdp/subscriptions","organizations_url":"https://api.github.com/users/erikvdp/orgs","repos_url":"https://api.github.com/users/erikvdp/repos","events_url":"https://api.github.com/users/erikvdp/events{/privacy}","received_events_url":"https://api.github.com/users/erikvdp/received_events","type":"User","site_admin":false},"body":"This function allows to draw the probability that a user is still alive for different units of time since the birth of the user. + I added a way to visualize this for the user.\r\n\r\n![schermafdruk 2015-03-16 18 07 33](https://cloud.githubusercontent.com/assets/203481/6671724/92588ed6-cc07-11e4-985b-cd10dd8070bf.png)\r\n","created_at":"2015-03-16T17:09:35Z","updated_at":"2015-03-17T01:09:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8b289648c3e7695ca703096df30ebf27e9bc258b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/9/commits","review_comments_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/9/comments","review_comment_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/issues/9/comments","statuses_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/statuses/ca0ed0ad0fc1e09521ee68d3ee3240c98cd23077","head":{"label":"erikvdp:feature-alive-path","ref":"feature-alive-path","sha":"ca0ed0ad0fc1e09521ee68d3ee3240c98cd23077","user":{"login":"erikvdp","id":203481,"avatar_url":"https://avatars.githubusercontent.com/u/203481?v=3","gravatar_id":"","url":"https://api.github.com/users/erikvdp","html_url":"https://github.com/erikvdp","followers_url":"https://api.github.com/users/erikvdp/followers","following_url":"https://api.github.com/users/erikvdp/following{/other_user}","gists_url":"https://api.github.com/users/erikvdp/gists{/gist_id}","starred_url":"https://api.github.com/users/erikvdp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikvdp/subscriptions","organizations_url":"https://api.github.com/users/erikvdp/orgs","repos_url":"https://api.github.com/users/erikvdp/repos","events_url":"https://api.github.com/users/erikvdp/events{/privacy}","received_events_url":"https://api.github.com/users/erikvdp/received_events","type":"User","site_admin":false},"repo":{"id":31057883,"name":"lifetimes","full_name":"erikvdp/lifetimes","owner":{"login":"erikvdp","id":203481,"avatar_url":"https://avatars.githubusercontent.com/u/203481?v=3","gravatar_id":"","url":"https://api.github.com/users/erikvdp","html_url":"https://github.com/erikvdp","followers_url":"https://api.github.com/users/erikvdp/followers","following_url":"https://api.github.com/users/erikvdp/following{/other_user}","gists_url":"https://api.github.com/users/erikvdp/gists{/gist_id}","starred_url":"https://api.github.com/users/erikvdp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikvdp/subscriptions","organizations_url":"https://api.github.com/users/erikvdp/orgs","repos_url":"https://api.github.com/users/erikvdp/repos","events_url":"https://api.github.com/users/erikvdp/events{/privacy}","received_events_url":"https://api.github.com/users/erikvdp/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/erikvdp/lifetimes","description":":collision: Customer lifetime value in Python","fork":true,"url":"https://api.github.com/repos/erikvdp/lifetimes","forks_url":"https://api.github.com/repos/erikvdp/lifetimes/forks","keys_url":"https://api.github.com/repos/erikvdp/lifetimes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/erikvdp/lifetimes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/erikvdp/lifetimes/teams","hooks_url":"https://api.github.com/repos/erikvdp/lifetimes/hooks","issue_events_url":"https://api.github.com/repos/erikvdp/lifetimes/issues/events{/number}","events_url":"https://api.github.com/repos/erikvdp/lifetimes/events","assignees_url":"https://api.github.com/repos/erikvdp/lifetimes/assignees{/user}","branches_url":"https://api.github.com/repos/erikvdp/lifetimes/branches{/branch}","tags_url":"https://api.github.com/repos/erikvdp/lifetimes/tags","blobs_url":"https://api.github.com/repos/erikvdp/lifetimes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/erikvdp/lifetimes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/erikvdp/lifetimes/git/refs{/sha}","trees_url":"https://api.github.com/repos/erikvdp/lifetimes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/erikvdp/lifetimes/statuses/{sha}","languages_url":"https://api.github.com/repos/erikvdp/lifetimes/languages","stargazers_url":"https://api.github.com/repos/erikvdp/lifetimes/stargazers","contributors_url":"https://api.github.com/repos/erikvdp/lifetimes/contributors","subscribers_url":"https://api.github.com/repos/erikvdp/lifetimes/subscribers","subscription_url":"https://api.github.com/repos/erikvdp/lifetimes/subscription","commits_url":"https://api.github.com/repos/erikvdp/lifetimes/commits{/sha}","git_commits_url":"https://api.github.com/repos/erikvdp/lifetimes/git/commits{/sha}","comments_url":"https://api.github.com/repos/erikvdp/lifetimes/comments{/number}","issue_comment_url":"https://api.github.com/repos/erikvdp/lifetimes/issues/comments{/number}","contents_url":"https://api.github.com/repos/erikvdp/lifetimes/contents/{+path}","compare_url":"https://api.github.com/repos/erikvdp/lifetimes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/erikvdp/lifetimes/merges","archive_url":"https://api.github.com/repos/erikvdp/lifetimes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/erikvdp/lifetimes/downloads","issues_url":"https://api.github.com/repos/erikvdp/lifetimes/issues{/number}","pulls_url":"https://api.github.com/repos/erikvdp/lifetimes/pulls{/number}","milestones_url":"https://api.github.com/repos/erikvdp/lifetimes/milestones{/number}","notifications_url":"https://api.github.com/repos/erikvdp/lifetimes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/erikvdp/lifetimes/labels{/name}","releases_url":"https://api.github.com/repos/erikvdp/lifetimes/releases{/id}","created_at":"2015-02-20T09:18:16Z","updated_at":"2015-03-09T13:47:55Z","pushed_at":"2015-03-16T17:07:13Z","git_url":"git://github.com/erikvdp/lifetimes.git","ssh_url":"git@github.com:erikvdp/lifetimes.git","clone_url":"https://github.com/erikvdp/lifetimes.git","svn_url":"https://github.com/erikvdp/lifetimes","homepage":"","size":705,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"CamDavidsonPilon:master","ref":"master","sha":"33a47ff69924310846af698a066eb43be3c57283","user":{"login":"CamDavidsonPilon","id":884032,"avatar_url":"https://avatars.githubusercontent.com/u/884032?v=3","gravatar_id":"","url":"https://api.github.com/users/CamDavidsonPilon","html_url":"https://github.com/CamDavidsonPilon","followers_url":"https://api.github.com/users/CamDavidsonPilon/followers","following_url":"https://api.github.com/users/CamDavidsonPilon/following{/other_user}","gists_url":"https://api.github.com/users/CamDavidsonPilon/gists{/gist_id}","starred_url":"https://api.github.com/users/CamDavidsonPilon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CamDavidsonPilon/subscriptions","organizations_url":"https://api.github.com/users/CamDavidsonPilon/orgs","repos_url":"https://api.github.com/users/CamDavidsonPilon/repos","events_url":"https://api.github.com/users/CamDavidsonPilon/events{/privacy}","received_events_url":"https://api.github.com/users/CamDavidsonPilon/received_events","type":"User","site_admin":false},"repo":{"id":28577939,"name":"lifetimes","full_name":"CamDavidsonPilon/lifetimes","owner":{"login":"CamDavidsonPilon","id":884032,"avatar_url":"https://avatars.githubusercontent.com/u/884032?v=3","gravatar_id":"","url":"https://api.github.com/users/CamDavidsonPilon","html_url":"https://github.com/CamDavidsonPilon","followers_url":"https://api.github.com/users/CamDavidsonPilon/followers","following_url":"https://api.github.com/users/CamDavidsonPilon/following{/other_user}","gists_url":"https://api.github.com/users/CamDavidsonPilon/gists{/gist_id}","starred_url":"https://api.github.com/users/CamDavidsonPilon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CamDavidsonPilon/subscriptions","organizations_url":"https://api.github.com/users/CamDavidsonPilon/orgs","repos_url":"https://api.github.com/users/CamDavidsonPilon/repos","events_url":"https://api.github.com/users/CamDavidsonPilon/events{/privacy}","received_events_url":"https://api.github.com/users/CamDavidsonPilon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/CamDavidsonPilon/lifetimes","description":"Customer lifetime value in Python","fork":false,"url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes","forks_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/forks","keys_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/teams","hooks_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/hooks","issue_events_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/issues/events{/number}","events_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/events","assignees_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/assignees{/user}","branches_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/branches{/branch}","tags_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/tags","blobs_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/git/refs{/sha}","trees_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/statuses/{sha}","languages_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/languages","stargazers_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/stargazers","contributors_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/contributors","subscribers_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/subscribers","subscription_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/subscription","commits_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/commits{/sha}","git_commits_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/git/commits{/sha}","comments_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/comments{/number}","issue_comment_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/issues/comments{/number}","contents_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/contents/{+path}","compare_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/merges","archive_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/downloads","issues_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/issues{/number}","pulls_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls{/number}","milestones_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/milestones{/number}","notifications_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/labels{/name}","releases_url":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/releases{/id}","created_at":"2014-12-29T02:47:57Z","updated_at":"2015-03-12T00:23:40Z","pushed_at":"2015-03-09T02:52:43Z","git_url":"git://github.com/CamDavidsonPilon/lifetimes.git","ssh_url":"git@github.com:CamDavidsonPilon/lifetimes.git","clone_url":"https://github.com/CamDavidsonPilon/lifetimes.git","svn_url":"https://github.com/CamDavidsonPilon/lifetimes","homepage":"","size":1087,"stargazers_count":46,"watchers_count":46,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":1,"forks":8,"open_issues":1,"watchers":46,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/9"},"html":{"href":"https://github.com/CamDavidsonPilon/lifetimes/pull/9"},"issue":{"href":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/issues/9"},"comments":{"href":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/CamDavidsonPilon/lifetimes/statuses/ca0ed0ad0fc1e09521ee68d3ee3240c98cd23077"}}}}