Skip to content

Commit

Permalink
Update notebook.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldorner committed Apr 13, 2023
1 parent 72a3bc9 commit 5861fa8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -22,17 +22,17 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"user_location = pd.DataFrame([], columns=['userid', 'month', 'country']) # load here your users' location for each month (captures user locations over time )\n",
"user_location = pd.DataFrame([], columns=['user_id', 'month', 'country']) # load here your users' location for each month (captures user locations over time )\n",
"\n",
"# if time information are not available, user_location can be a dict mapping persons to a country (static; does not capture user locations over time)\n",
"user_location = {\n",
" 'c8b39e436e0d96f0c8f7c66908a02d15': 'Germany',\n",
" '3425a6f8362416088ea186018a0f5d71': 'Sweden'\n",
"}\n"
"}"
]
},
{
Expand All @@ -44,7 +44,7 @@
"if type(user_location) == dict:\n",
" humans = set(user_location)\n",
"else:\n",
" humans = set(user_location.userid)"
" humans = set(user_location.user_id)"
]
},
{
Expand Down Expand Up @@ -148,7 +148,7 @@
"metadata": {},
"outputs": [],
"source": [
"activities = pd.DataFrame(events, columns=['userid', 'timestamp', 'action', 'pr_id']).dropna()\n",
"activities = pd.DataFrame(events, columns=['user_id', 'timestamp', 'action', 'pr_id']).dropna()\n",
"activities.timestamp = pd.to_datetime(activities.timestamp).dt.tz_localize(None)\n",
"activities['month'] = activities.timestamp.to_numpy().astype('datetime64[M]')"
]
Expand All @@ -160,9 +160,9 @@
"outputs": [],
"source": [
"if type(user_location) == dict:\n",
" activities['country'] = activities.userid.replace(user_location)\n",
" activities['country'] = activities.user_id.replace(user_location)\n",
"else:\n",
" activities = activities.merge(user_location, how='left', left_on=['userid', 'month'], right_on=['userid', 'month'], validate='m:1')"
" activities = activities.merge(user_location, how='left', left_on=['user_id', 'month'], right_on=['user_id', 'month'], validate='m:1')"
]
},
{
Expand All @@ -184,7 +184,7 @@
},
{
"cell_type": "code",
"execution_count": 83,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down

0 comments on commit 5861fa8

Please sign in to comment.