diff --git a/191202_sql_lecture.ipynb b/191202_sql_lecture.ipynb index 395dac8..1659de2 100644 --- a/191202_sql_lecture.ipynb +++ b/191202_sql_lecture.ipynb @@ -11,9 +11,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Connected: jovyan@si330'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "%load_ext sql\n", "%sql postgres://jovyan:si330studentuser@localhost:5432/si330" @@ -21,23 +32,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "Done.\n", + "Done.\n", + "Done.\n", + "Done.\n", + "Done.\n", + "Done.\n", + "Done.\n" + ] + }, + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "%%sql \n", + "%%sql\n", "drop table if exists assignment;\n", "drop table if exists users;\n", - "drop table if exists assignment_attempt;\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%%sql\n", + "drop table if exists assignment_attempt;\n", + "\n", "CREATE TABLE \"assignment\" (\n", " \"id\" integer,\n", " \"descr\" varchar,\n", @@ -63,45 +91,385 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n" + ] + }, + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "%sql insert into users (username) values ('brooksch')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
username
brooksch
" + ], + "text/plain": [ + "[('brooksch',)]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "%sql select * from users" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
username
brooksch
" + ], + "text/plain": [ + "[('brooksch',)]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%sql select username from users" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "3 rows affected.\n" + ] + }, + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "%sql insert into users (username) values ('cab938-1'),('cab938-2'),('cab938-3')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "4 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
username
brooksch
cab938-1
cab938-2
cab938-3
" + ], + "text/plain": [ + "[('brooksch',), ('cab938-1',), ('cab938-2',), ('cab938-3',)]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "%sql select * from users" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import string\n", + "string.ascii_letters" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['F', 'm', 'K', 'Q', 'C', 'x']" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import random\n", + "random.sample(string.ascii_letters,6)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'QjVXaB'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst=random.sample(string.ascii_letters,6)\n", + "our_strng=\"\"\n", + "for i in lst:\n", + " our_strng+=i\n", + "our_strng" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'SqVdcX'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\".join(random.sample(string.ascii_letters,6))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I'm going to try and insert 'suiWcd' as a user!\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + "I'm going to try and insert 'mwrjMG' as a user!\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + "I'm going to try and insert 'viezHE' as a user!\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + "I'm going to try and insert 'ObeIuf' as a user!\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + "I'm going to try and insert 'ZGMSye' as a user!\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + "I'm going to try and insert 'inRgxM' as a user!\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + "I'm going to try and insert 'qJOiQn' as a user!\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + "I'm going to try and insert 'wMaRtb' as a user!\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + "I'm going to try and insert 'sxjXtv' as a user!\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + "I'm going to try and insert 'uJmLWs' as a user!\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "14 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
username
brooksch
cab938-1
cab938-2
cab938-3
suiWcd
mwrjMG
viezHE
ObeIuf
ZGMSye
inRgxM
qJOiQn
wMaRtb
sxjXtv
uJmLWs
" + ], + "text/plain": [ + "[('brooksch',),\n", + " ('cab938-1',),\n", + " ('cab938-2',),\n", + " ('cab938-3',),\n", + " ('suiWcd',),\n", + " ('mwrjMG',),\n", + " ('viezHE',),\n", + " ('ObeIuf',),\n", + " ('ZGMSye',),\n", + " ('inRgxM',),\n", + " ('qJOiQn',),\n", + " ('wMaRtb',),\n", + " ('sxjXtv',),\n", + " ('uJmLWs',)]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import string\n", "import random\n", @@ -109,10 +477,154 @@ " random_characters=random.sample(string.ascii_letters,6)\n", " user=\"\".join(random_characters)\n", " user=\"'\"+user+\"'\"\n", + " print(\"I'm going to try and insert {} as a user!\".format(user))\n", " %sql insert into users (username) values ($user)\n", "%sql select * from users" ] }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "10 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "24 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
username
brooksch
cab938-1
cab938-2
cab938-3
suiWcd
mwrjMG
viezHE
ObeIuf
ZGMSye
inRgxM
qJOiQn
wMaRtb
sxjXtv
uJmLWs
wQGICg
zYBbMX
zxvgFq
LfIkWO
pHVWTY
dUtuPp
qzEHWO
jCKTuv
pqsUZf
glIxbE
" + ], + "text/plain": [ + "[('brooksch',),\n", + " ('cab938-1',),\n", + " ('cab938-2',),\n", + " ('cab938-3',),\n", + " ('suiWcd',),\n", + " ('mwrjMG',),\n", + " ('viezHE',),\n", + " ('ObeIuf',),\n", + " ('ZGMSye',),\n", + " ('inRgxM',),\n", + " ('qJOiQn',),\n", + " ('wMaRtb',),\n", + " ('sxjXtv',),\n", + " ('uJmLWs',),\n", + " ('wQGICg',),\n", + " ('zYBbMX',),\n", + " ('zxvgFq',),\n", + " ('LfIkWO',),\n", + " ('pHVWTY',),\n", + " ('dUtuPp',),\n", + " ('qzEHWO',),\n", + " ('jCKTuv',),\n", + " ('pqsUZf',),\n", + " ('glIxbE',)]" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import string\n", + "import random\n", + "sql_string=\"insert into users (username) values \"\n", + "for i in range(0,10):\n", + " random_characters=random.sample(string.ascii_letters,6)\n", + " user=\"\".join(random_characters)\n", + " user=\"('\"+user+\"'),\"\n", + " sql_string+=user\n", + "sql_string=sql_string[0:-1]\n", + "\n", + "%sql $sql_string\n", + "%sql select * from users" + ] + }, { "cell_type": "code", "execution_count": null, @@ -124,18 +636,229 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n" + ] + } + ], "source": [ - "# YOUR CODE HERE" + "for i in range(1,6):\n", + " %sql insert into assignment (id,descr,num_points) values ($i,'sample assignment',100)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "6 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
iddescrnum_points
0sample assignment100
1sample assignment100
2sample assignment100
3sample assignment100
4sample assignment100
5sample assignment100
" + ], + "text/plain": [ + "[(0, 'sample assignment', 100),\n", + " (1, 'sample assignment', 100),\n", + " (2, 'sample assignment', 100),\n", + " (3, 'sample assignment', 100),\n", + " (4, 'sample assignment', 100),\n", + " (5, 'sample assignment', 100)]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%sql select * from assignment" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "24 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
username
brooksch
cab938-1
cab938-2
cab938-3
suiWcd
mwrjMG
viezHE
ObeIuf
ZGMSye
inRgxM
qJOiQn
wMaRtb
sxjXtv
uJmLWs
wQGICg
zYBbMX
zxvgFq
LfIkWO
pHVWTY
dUtuPp
qzEHWO
jCKTuv
pqsUZf
glIxbE
" + ], + "text/plain": [ + "[('brooksch',),\n", + " ('cab938-1',),\n", + " ('cab938-2',),\n", + " ('cab938-3',),\n", + " ('suiWcd',),\n", + " ('mwrjMG',),\n", + " ('viezHE',),\n", + " ('ObeIuf',),\n", + " ('ZGMSye',),\n", + " ('inRgxM',),\n", + " ('qJOiQn',),\n", + " ('wMaRtb',),\n", + " ('sxjXtv',),\n", + " ('uJmLWs',),\n", + " ('wQGICg',),\n", + " ('zYBbMX',),\n", + " ('zxvgFq',),\n", + " ('LfIkWO',),\n", + " ('pHVWTY',),\n", + " ('dUtuPp',),\n", + " ('qzEHWO',),\n", + " ('jCKTuv',),\n", + " ('pqsUZf',),\n", + " ('glIxbE',)]" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Now lets generate some random user attempt data\n", "users=%sql select username from users\n", @@ -144,9 +867,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "# Wait, what is this object?\n", "print(type(users))" @@ -154,9 +885,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('brooksch',)\n", + "('cab938-1',)\n", + "('cab938-2',)\n", + "('cab938-3',)\n", + "('suiWcd',)\n", + "('mwrjMG',)\n", + "('viezHE',)\n", + "('ObeIuf',)\n", + "('ZGMSye',)\n", + "('inRgxM',)\n", + "('qJOiQn',)\n", + "('wMaRtb',)\n", + "('sxjXtv',)\n", + "('uJmLWs',)\n", + "('wQGICg',)\n", + "('zYBbMX',)\n", + "('zxvgFq',)\n", + "('LfIkWO',)\n", + "('pHVWTY',)\n", + "('dUtuPp',)\n", + "('qzEHWO',)\n", + "('jCKTuv',)\n", + "('pqsUZf',)\n", + "('glIxbE',)\n" + ] + } + ], "source": [ "# We can leave it as is to iterate over it\n", "for user in users:\n", @@ -165,9 +927,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "brooksch\n", + "cab938-1\n", + "cab938-2\n", + "cab938-3\n", + "suiWcd\n", + "mwrjMG\n", + "viezHE\n", + "ObeIuf\n", + "ZGMSye\n", + "inRgxM\n", + "qJOiQn\n", + "wMaRtb\n", + "sxjXtv\n", + "uJmLWs\n", + "wQGICg\n", + "zYBbMX\n", + "zxvgFq\n", + "LfIkWO\n", + "pHVWTY\n", + "dUtuPp\n", + "qzEHWO\n", + "jCKTuv\n", + "pqsUZf\n", + "glIxbE\n" + ] + } + ], "source": [ "# Notice that every element in the list is a tuple, but a tuple of length one.\n", "clean_users=[]\n", @@ -178,9 +971,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "6 rows affected.\n", + "[0, 1, 2, 3, 4, 5]\n" + ] + } + ], "source": [ "# Let's get the assignments list as well\n", "assignments=%sql select id from assignment\n", @@ -190,9 +993,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "# Notice that %sql unpacks the correct type information for us too\n", "print(type(assignments[0]))" @@ -200,23 +1011,355 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['brooksch', 'cab938-1', 'cab938-2', 'cab938-3', 'suiWcd', 'mwrjMG', 'viezHE', 'ObeIuf', 'ZGMSye', 'inRgxM', 'qJOiQn', 'wMaRtb', 'sxjXtv', 'uJmLWs', 'wQGICg', 'zYBbMX', 'zxvgFq', 'LfIkWO', 'pHVWTY', 'dUtuPp', 'qzEHWO', 'jCKTuv', 'pqsUZf', 'glIxbE']\n", + "[0, 1, 2, 3, 4, 5]\n" + ] + } + ], + "source": [ + "print(clean_users)\n", + "print(assignments)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n", + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n" + ] + } + ], "source": [ "# Ok, now we have a list of assignments and a list of users. These are our foreign keys in assignment_attempt!\n", "# So lets make some attempts\n", "import datetime\n", "\n", "for i in range(0,100):\n", - " # What do we want to do here?" + " user=random.choice(clean_users)\n", + " assignment=random.choice(assignments)\n", + " points=random.randint(0,100)\n", + " timestamp=datetime.datetime.now()\n", + " \n", + " user=\"'{}'\".format(user)\n", + " timestamp=\"'{}'\".format(timestamp)\n", + " \n", + " %sql insert into assignment_attempt (timestamp,\"user\",assignment,points_awarded) values ($timestamp, $user, $assignment, $points)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "10 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
timestampuserassignmentpoints_awarded
2019-12-02 14:31:24.406072viezHE576
2019-12-02 14:31:24.411427qJOiQn029
2019-12-02 14:31:24.414247qJOiQn588
2019-12-02 14:31:24.416857jCKTuv599
2019-12-02 14:31:24.419301cab938-1032
2019-12-02 14:31:24.421968cab938-238
2019-12-02 14:31:24.424329viezHE017
2019-12-02 14:31:24.426644qzEHWO527
2019-12-02 14:31:24.428901pHVWTY111
2019-12-02 14:31:24.431243ObeIuf561
" + ], + "text/plain": [ + "[(datetime.datetime(2019, 12, 2, 14, 31, 24, 406072), 'viezHE', 5, 76),\n", + " (datetime.datetime(2019, 12, 2, 14, 31, 24, 411427), 'qJOiQn', 0, 29),\n", + " (datetime.datetime(2019, 12, 2, 14, 31, 24, 414247), 'qJOiQn', 5, 88),\n", + " (datetime.datetime(2019, 12, 2, 14, 31, 24, 416857), 'jCKTuv', 5, 99),\n", + " (datetime.datetime(2019, 12, 2, 14, 31, 24, 419301), 'cab938-1', 0, 32),\n", + " (datetime.datetime(2019, 12, 2, 14, 31, 24, 421968), 'cab938-2', 3, 8),\n", + " (datetime.datetime(2019, 12, 2, 14, 31, 24, 424329), 'viezHE', 0, 17),\n", + " (datetime.datetime(2019, 12, 2, 14, 31, 24, 426644), 'qzEHWO', 5, 27),\n", + " (datetime.datetime(2019, 12, 2, 14, 31, 24, 428901), 'pHVWTY', 1, 11),\n", + " (datetime.datetime(2019, 12, 2, 14, 31, 24, 431243), 'ObeIuf', 5, 61)]" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Let's see what we have in there\n", "%sql select * from assignment_attempt limit 10" @@ -224,9 +1367,472 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "100 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
points_awarded
76
29
88
99
32
8
17
27
11
61
38
23
54
90
39
58
100
6
79
14
56
18
22
86
76
91
18
28
3
68
8
53
50
15
67
33
74
22
68
90
44
75
68
27
83
67
58
16
72
86
95
57
11
49
74
32
52
56
26
60
50
41
94
30
96
82
24
80
99
23
69
91
29
46
40
79
62
41
0
68
52
46
92
40
25
74
83
40
21
75
22
26
47
35
85
86
25
69
5
43
" + ], + "text/plain": [ + "[(76,),\n", + " (29,),\n", + " (88,),\n", + " (99,),\n", + " (32,),\n", + " (8,),\n", + " (17,),\n", + " (27,),\n", + " (11,),\n", + " (61,),\n", + " (38,),\n", + " (23,),\n", + " (54,),\n", + " (90,),\n", + " (39,),\n", + " (58,),\n", + " (100,),\n", + " (6,),\n", + " (79,),\n", + " (14,),\n", + " (56,),\n", + " (18,),\n", + " (22,),\n", + " (86,),\n", + " (76,),\n", + " (91,),\n", + " (18,),\n", + " (28,),\n", + " (3,),\n", + " (68,),\n", + " (8,),\n", + " (53,),\n", + " (50,),\n", + " (15,),\n", + " (67,),\n", + " (33,),\n", + " (74,),\n", + " (22,),\n", + " (68,),\n", + " (90,),\n", + " (44,),\n", + " (75,),\n", + " (68,),\n", + " (27,),\n", + " (83,),\n", + " (67,),\n", + " (58,),\n", + " (16,),\n", + " (72,),\n", + " (86,),\n", + " (95,),\n", + " (57,),\n", + " (11,),\n", + " (49,),\n", + " (74,),\n", + " (32,),\n", + " (52,),\n", + " (56,),\n", + " (26,),\n", + " (60,),\n", + " (50,),\n", + " (41,),\n", + " (94,),\n", + " (30,),\n", + " (96,),\n", + " (82,),\n", + " (24,),\n", + " (80,),\n", + " (99,),\n", + " (23,),\n", + " (69,),\n", + " (91,),\n", + " (29,),\n", + " (46,),\n", + " (40,),\n", + " (79,),\n", + " (62,),\n", + " (41,),\n", + " (0,),\n", + " (68,),\n", + " (52,),\n", + " (46,),\n", + " (92,),\n", + " (40,),\n", + " (25,),\n", + " (74,),\n", + " (83,),\n", + " (40,),\n", + " (21,),\n", + " (75,),\n", + " (22,),\n", + " (26,),\n", + " (47,),\n", + " (35,),\n", + " (85,),\n", + " (86,),\n", + " (25,),\n", + " (69,),\n", + " (5,),\n", + " (43,)]" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%sql select points_awarded from assignment_attempt" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
max
100
" + ], + "text/plain": [ + "[(100,)]" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Ok, let's amp this up a bit. We can do some aggregations on this data just like in pandas. We do this by\n", "# indicating the sql function we want to run around the selection parameters\n", @@ -235,12 +1841,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
max_columnbluebirdmean
100051.3800000000000000
" + ], + "text/plain": [ + "[(100, 0, Decimal('51.3800000000000000'))]" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# You can have multiple values being projected in that select, and you can name the return columns with the as keyword\n", - "%sql select max(points_awarded) as max, min(points_awarded) as min, avg(points_awarded) as mean from assignment_attempt" + "%sql select max(points_awarded) as max_column, min(points_awarded) as bluebird, avg(points_awarded) as mean from assignment_attempt" ] }, { @@ -254,18 +1893,80 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stddevcount
27.8044324640238727100
" + ], + "text/plain": [ + "[(Decimal('27.8044324640238727'), 100)]" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# YOUR CODE HERE" + "%sql select stddev(points_awarded), count(points_awarded) from assignment_attempt" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "1 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
useraverage
jovyan51.3800000000000000
" + ], + "text/plain": [ + "[('jovyan', Decimal('51.3800000000000000'))]" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# What if you want to find out the average of each person's score?\n", "%sql select user, avg(points_awarded) as average from assignment_attempt" @@ -282,9 +1983,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "(psycopg2.errors.GroupingError) column \"assignment_attempt.user\" must appear in the GROUP BY clause or be used in an aggregate function\n", + "LINE 1: select \"user\", avg(points_awarded) as average from assignmen...\n", + " ^\n", + "\n", + "[SQL: select \"user\", avg(points_awarded) as average from assignment_attempt]\n", + "(Background on this error at: http://sqlalche.me/e/f405)\n" + ] + } + ], "source": [ "%sql select \"user\", avg(points_awarded) as average from assignment_attempt" ] @@ -301,9 +2016,90 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
timestampuserassignmentpoints_awarded
02019-12-02 14:31:24.406072viezHE576
12019-12-02 14:31:24.411427qJOiQn029
22019-12-02 14:31:24.414247qJOiQn588
32019-12-02 14:31:24.416857jCKTuv599
42019-12-02 14:31:24.419301cab938-1032
\n", + "
" + ], + "text/plain": [ + " timestamp user assignment points_awarded\n", + "0 2019-12-02 14:31:24.406072 viezHE 5 76\n", + "1 2019-12-02 14:31:24.411427 qJOiQn 0 29\n", + "2 2019-12-02 14:31:24.414247 qJOiQn 5 88\n", + "3 2019-12-02 14:31:24.416857 jCKTuv 5 99\n", + "4 2019-12-02 14:31:24.419301 cab938-1 0 32" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "host=\"localhost\"\n", "dbname=\"si330\"\n", @@ -321,9 +2117,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "('Could not convert viezHEqJOiQnqJOiQnjCKTuvcab938-1cab938-2viezHEqzEHWOpHVWTYObeIufqzEHWOpHVWTYjCKTuvwMaRtbwMaRtbcab938-3viezHEObeIufzxvgFqpqsUZfwQGICgdUtuPpinRgxMObeIufwMaRtbpHVWTYObeIufsxjXtvpHVWTYqzEHWOsxjXtvbrookschwMaRtbglIxbEviezHEviezHEzYBbMXbrookschcab938-2cab938-1LfIkWOsuiWcdviezHEinRgxMqzEHWOinRgxMviezHEinRgxMpqsUZfsxjXtvsxjXtvsuiWcdglIxbEObeIufLfIkWOsxjXtvbrookschpqsUZfdUtuPpLfIkWOpHVWTYsuiWcdmwrjMGviezHEviezHEwQGICgbrookschcab938-1zxvgFqjCKTuvcab938-3pHVWTYwMaRtbqJOiQnsuiWcdjCKTuvmwrjMGObeIufcab938-2sxjXtvjCKTuvsxjXtvsuiWcdinRgxMviezHEviezHELfIkWOLfIkWOObeIufpqsUZfqzEHWOsxjXtvpHVWTYpHVWTYqJOiQnsuiWcdzxvgFqviezHEqJOiQnwMaRtb to numeric', 'occurred at index user')", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36m_ensure_numeric\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 1303\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1304\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1305\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: could not convert string to float: 'viezHEqJOiQnqJOiQnjCKTuvcab938-1cab938-2viezHEqzEHWOpHVWTYObeIufqzEHWOpHVWTYjCKTuvwMaRtbwMaRtbcab938-3viezHEObeIufzxvgFqpqsUZfwQGICgdUtuPpinRgxMObeIufwMaRtbpHVWTYObeIufsxjXtvpHVWTYqzEHWOsxjXtvbrookschwMaRtbglIxbEviezHEviezHEzYBbMXbrookschcab938-2cab938-1LfIkWOsuiWcdviezHEinRgxMqzEHWOinRgxMviezHEinRgxMpqsUZfsxjXtvsxjXtvsuiWcdglIxbEObeIufLfIkWOsxjXtvbrookschpqsUZfdUtuPpLfIkWOpHVWTYsuiWcdmwrjMGviezHEviezHEwQGICgbrookschcab938-1zxvgFqjCKTuvcab938-3pHVWTYwMaRtbqJOiQnsuiWcdjCKTuvmwrjMGObeIufcab938-2sxjXtvjCKTuvsxjXtvsuiWcdinRgxMviezHEviezHELfIkWOLfIkWOObeIufpqsUZfqzEHWOsxjXtvpHVWTYpHVWTYqJOiQnsuiWcdzxvgFqviezHEqJOiQnwMaRtb'", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36m_ensure_numeric\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 1306\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1307\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcomplex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1308\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: complex() arg is a malformed string", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36mf\u001b[0;34m(values, axis, skipna, **kwds)\u001b[0m\n\u001b[1;32m 119\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 120\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0malt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskipna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mskipna\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 121\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36mnanmean\u001b[0;34m(values, axis, skipna, mask)\u001b[0m\n\u001b[1;32m 550\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_get_counts\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmask\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype_count\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 551\u001b[0;31m \u001b[0mthe_sum\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_ensure_numeric\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype_sum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 552\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36m_ensure_numeric\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 1309\u001b[0m raise TypeError(\n\u001b[0;32m-> 1310\u001b[0;31m \u001b[0;34m\"Could not convert {value!s} to numeric\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1311\u001b[0m )\n", + "\u001b[0;31mTypeError\u001b[0m: Could not convert viezHEqJOiQnqJOiQnjCKTuvcab938-1cab938-2viezHEqzEHWOpHVWTYObeIufqzEHWOpHVWTYjCKTuvwMaRtbwMaRtbcab938-3viezHEObeIufzxvgFqpqsUZfwQGICgdUtuPpinRgxMObeIufwMaRtbpHVWTYObeIufsxjXtvpHVWTYqzEHWOsxjXtvbrookschwMaRtbglIxbEviezHEviezHEzYBbMXbrookschcab938-2cab938-1LfIkWOsuiWcdviezHEinRgxMqzEHWOinRgxMviezHEinRgxMpqsUZfsxjXtvsxjXtvsuiWcdglIxbEObeIufLfIkWOsxjXtvbrookschpqsUZfdUtuPpLfIkWOpHVWTYsuiWcdmwrjMGviezHEviezHEwQGICgbrookschcab938-1zxvgFqjCKTuvcab938-3pHVWTYwMaRtbqJOiQnsuiWcdjCKTuvmwrjMGObeIufcab938-2sxjXtvjCKTuvsxjXtvsuiWcdinRgxMviezHEviezHELfIkWOLfIkWOObeIufpqsUZfqzEHWOsxjXtvpHVWTYpHVWTYqJOiQnsuiWcdzxvgFqviezHEqJOiQnwMaRtb to numeric", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36m_ensure_numeric\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 1303\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1304\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1305\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: could not convert string to float: 'viezHEqJOiQnqJOiQnjCKTuvcab938-1cab938-2viezHEqzEHWOpHVWTYObeIufqzEHWOpHVWTYjCKTuvwMaRtbwMaRtbcab938-3viezHEObeIufzxvgFqpqsUZfwQGICgdUtuPpinRgxMObeIufwMaRtbpHVWTYObeIufsxjXtvpHVWTYqzEHWOsxjXtvbrookschwMaRtbglIxbEviezHEviezHEzYBbMXbrookschcab938-2cab938-1LfIkWOsuiWcdviezHEinRgxMqzEHWOinRgxMviezHEinRgxMpqsUZfsxjXtvsxjXtvsuiWcdglIxbEObeIufLfIkWOsxjXtvbrookschpqsUZfdUtuPpLfIkWOpHVWTYsuiWcdmwrjMGviezHEviezHEwQGICgbrookschcab938-1zxvgFqjCKTuvcab938-3pHVWTYwMaRtbqJOiQnsuiWcdjCKTuvmwrjMGObeIufcab938-2sxjXtvjCKTuvsxjXtvsuiWcdinRgxMviezHEviezHELfIkWOLfIkWOObeIufpqsUZfqzEHWOsxjXtvpHVWTYpHVWTYqJOiQnsuiWcdzxvgFqviezHEqJOiQnwMaRtb'", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36m_ensure_numeric\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 1306\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1307\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcomplex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1308\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: complex() arg is a malformed string", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"user\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"points_awarded\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36mapply\u001b[0;34m(self, func, axis, broadcast, raw, reduce, result_type, args, **kwds)\u001b[0m\n\u001b[1;32m 6911\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6912\u001b[0m )\n\u001b[0;32m-> 6913\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mop\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_result\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6914\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6915\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mapplymap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/apply.py\u001b[0m in \u001b[0;36mget_result\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 184\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_raw\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 185\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 186\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_standard\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 187\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 188\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mapply_empty_result\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/apply.py\u001b[0m in \u001b[0;36mapply_standard\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 290\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 291\u001b[0m \u001b[0;31m# compute the result using the series generator\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 292\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_series_generator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 293\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 294\u001b[0m \u001b[0;31m# wrap results\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/apply.py\u001b[0m in \u001b[0;36mapply_series_generator\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 319\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 320\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mv\u001b[0m \u001b[0;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mseries_gen\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 321\u001b[0;31m \u001b[0mresults\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 322\u001b[0m \u001b[0mkeys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 323\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m<__array_function__ internals>\u001b[0m in \u001b[0;36mmean\u001b[0;34m(*args, **kwargs)\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py\u001b[0m in \u001b[0;36mmean\u001b[0;34m(a, axis, dtype, out, keepdims)\u001b[0m\n\u001b[1;32m 3252\u001b[0m \u001b[0;32mpass\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3253\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3254\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3255\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3256\u001b[0m return _methods._mean(a, axis=axis, dtype=dtype,\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36mstat_func\u001b[0;34m(self, axis, skipna, level, numeric_only, **kwargs)\u001b[0m\n\u001b[1;32m 11616\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_agg_by_level\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlevel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskipna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mskipna\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11617\u001b[0m return self._reduce(\n\u001b[0;32m> 11618\u001b[0;31m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskipna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mskipna\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumeric_only\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnumeric_only\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 11619\u001b[0m )\n\u001b[1;32m 11620\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/series.py\u001b[0m in \u001b[0;36m_reduce\u001b[0;34m(self, op, name, axis, skipna, numeric_only, filter_type, **kwds)\u001b[0m\n\u001b[1;32m 4085\u001b[0m )\n\u001b[1;32m 4086\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mall\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"ignore\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4087\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdelegate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskipna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mskipna\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4088\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4089\u001b[0m \u001b[0;31m# TODO(EA) dispatch to Index\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36m_f\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 68\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 69\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minvalid\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"ignore\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 70\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 71\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mValueError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 72\u001b[0m \u001b[0;31m# we want to transform an object array\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36mf\u001b[0;34m(values, axis, skipna, **kwds)\u001b[0m\n\u001b[1;32m 121\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 122\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 123\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0malt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskipna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mskipna\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 124\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mValueError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 125\u001b[0m \u001b[0;31m# we want to transform an object array\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36mnanmean\u001b[0;34m(values, axis, skipna, mask)\u001b[0m\n\u001b[1;32m 549\u001b[0m \u001b[0mdtype_count\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 550\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_get_counts\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmask\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype_count\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 551\u001b[0;31m \u001b[0mthe_sum\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_ensure_numeric\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype_sum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 552\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 553\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0maxis\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mthe_sum\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"ndim\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py\u001b[0m in \u001b[0;36m_ensure_numeric\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 1308\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1309\u001b[0m raise TypeError(\n\u001b[0;32m-> 1310\u001b[0;31m \u001b[0;34m\"Could not convert {value!s} to numeric\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1311\u001b[0m )\n\u001b[1;32m 1312\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: ('Could not convert viezHEqJOiQnqJOiQnjCKTuvcab938-1cab938-2viezHEqzEHWOpHVWTYObeIufqzEHWOpHVWTYjCKTuvwMaRtbwMaRtbcab938-3viezHEObeIufzxvgFqpqsUZfwQGICgdUtuPpinRgxMObeIufwMaRtbpHVWTYObeIufsxjXtvpHVWTYqzEHWOsxjXtvbrookschwMaRtbglIxbEviezHEviezHEzYBbMXbrookschcab938-2cab938-1LfIkWOsuiWcdviezHEinRgxMqzEHWOinRgxMviezHEinRgxMpqsUZfsxjXtvsxjXtvsuiWcdglIxbEObeIufLfIkWOsxjXtvbrookschpqsUZfdUtuPpLfIkWOpHVWTYsuiWcdmwrjMGviezHEviezHEwQGICgbrookschcab938-1zxvgFqjCKTuvcab938-3pHVWTYwMaRtbqJOiQnsuiWcdjCKTuvmwrjMGObeIufcab938-2sxjXtvjCKTuvsxjXtvsuiWcdinRgxMviezHEviezHELfIkWOLfIkWOObeIufpqsUZfqzEHWOsxjXtvpHVWTYpHVWTYqJOiQnsuiWcdzxvgFqviezHEqJOiQnwMaRtb to numeric', 'occurred at index user')" + ] + } + ], "source": [ "df[[\"user\",\"points_awarded\"]].apply(np.mean)" ] @@ -340,23 +2182,437 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
points_awarded
user
LfIkWO60.200000
ObeIuf40.285714
brooksch37.750000
cab938-167.333333
cab938-225.333333
cab938-363.500000
dUtuPp22.000000
glIxbE13.000000
inRgxM34.400000
jCKTuv61.400000
mwrjMG78.000000
pHVWTY43.875000
pqsUZf54.250000
qJOiQn50.600000
qzEHWO47.600000
suiWcd65.166667
sxjXtv48.625000
viezHE59.416667
wMaRtb54.500000
wQGICg69.000000
zYBbMX74.000000
zxvgFq67.666667
\n", + "
" + ], + "text/plain": [ + " points_awarded\n", + "user \n", + "LfIkWO 60.200000\n", + "ObeIuf 40.285714\n", + "brooksch 37.750000\n", + "cab938-1 67.333333\n", + "cab938-2 25.333333\n", + "cab938-3 63.500000\n", + "dUtuPp 22.000000\n", + "glIxbE 13.000000\n", + "inRgxM 34.400000\n", + "jCKTuv 61.400000\n", + "mwrjMG 78.000000\n", + "pHVWTY 43.875000\n", + "pqsUZf 54.250000\n", + "qJOiQn 50.600000\n", + "qzEHWO 47.600000\n", + "suiWcd 65.166667\n", + "sxjXtv 48.625000\n", + "viezHE 59.416667\n", + "wMaRtb 54.500000\n", + "wQGICg 69.000000\n", + "zYBbMX 74.000000\n", + "zxvgFq 67.666667" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "df[[\"user\",\"points_awarded\"]].groupby(\"user\").apply(np.mean)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "22 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
useravg
jCKTuv61.4000000000000000
pqsUZf54.2500000000000000
qzEHWO47.6000000000000000
sxjXtv48.6250000000000000
cab938-167.3333333333333333
viezHE59.4166666666666667
brooksch37.7500000000000000
wQGICg69.0000000000000000
wMaRtb54.5000000000000000
glIxbE13.0000000000000000
cab938-363.5000000000000000
LfIkWO60.2000000000000000
zxvgFq67.6666666666666667
inRgxM34.4000000000000000
dUtuPp22.0000000000000000
qJOiQn50.6000000000000000
cab938-225.3333333333333333
mwrjMG78.0000000000000000
ObeIuf40.2857142857142857
zYBbMX74.0000000000000000
pHVWTY43.8750000000000000
suiWcd65.1666666666666667
" + ], + "text/plain": [ + "[('jCKTuv', Decimal('61.4000000000000000')),\n", + " ('pqsUZf', Decimal('54.2500000000000000')),\n", + " ('qzEHWO', Decimal('47.6000000000000000')),\n", + " ('sxjXtv', Decimal('48.6250000000000000')),\n", + " ('cab938-1', Decimal('67.3333333333333333')),\n", + " ('viezHE', Decimal('59.4166666666666667')),\n", + " ('brooksch', Decimal('37.7500000000000000')),\n", + " ('wQGICg', Decimal('69.0000000000000000')),\n", + " ('wMaRtb', Decimal('54.5000000000000000')),\n", + " ('glIxbE', Decimal('13.0000000000000000')),\n", + " ('cab938-3', Decimal('63.5000000000000000')),\n", + " ('LfIkWO', Decimal('60.2000000000000000')),\n", + " ('zxvgFq', Decimal('67.6666666666666667')),\n", + " ('inRgxM', Decimal('34.4000000000000000')),\n", + " ('dUtuPp', Decimal('22.0000000000000000')),\n", + " ('qJOiQn', Decimal('50.6000000000000000')),\n", + " ('cab938-2', Decimal('25.3333333333333333')),\n", + " ('mwrjMG', Decimal('78.0000000000000000')),\n", + " ('ObeIuf', Decimal('40.2857142857142857')),\n", + " ('zYBbMX', Decimal('74.0000000000000000')),\n", + " ('pHVWTY', Decimal('43.8750000000000000')),\n", + " ('suiWcd', Decimal('65.1666666666666667'))]" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# We can do the same thing in SQL!\n", "%sql select \"user\", avg(points_awarded) from assignment_attempt group by \"user\"" ] }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "(psycopg2.errors.SyntaxError) syntax error at or near \"#\"\n", + "LINE 1: # whats the deal with double quotes?\n", + " ^\n", + "\n", + "[SQL: # whats the deal with double quotes?\n", + "# double quotes mean the precise or exact representation of the string should be used\n", + "# this is useful for reserved words\n", + "create table as \"Questions\" (\n", + "id integer\n", + ");]\n", + "(Background on this error at: http://sqlalche.me/e/f405)\n" + ] + } + ], + "source": [ + "# whats the deal with double quotes?\n", + "# double quotes mean the precise or exact representation of the string should be used\n", + "# this is useful for reserved words" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "Done.\n" + ] + }, + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%%sql\n", + "drop table \"Questions\";\n" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "Done.\n" + ] + }, + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%%sql\n", + "create table Questions (\n", + "id integer\n", + ");" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * postgres://jovyan:***@localhost:5432/si330\n", + "0 rows affected.\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + "
id
" + ], + "text/plain": [ + "[]" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "%sql select * from questions" + ] + }, { "cell_type": "code", "execution_count": null,