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",
+ " username | \n",
+ "
\n",
+ " \n",
+ " brooksch | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " username | \n",
+ "
\n",
+ " \n",
+ " brooksch | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " username | \n",
+ "
\n",
+ " \n",
+ " brooksch | \n",
+ "
\n",
+ " \n",
+ " cab938-1 | \n",
+ "
\n",
+ " \n",
+ " cab938-2 | \n",
+ "
\n",
+ " \n",
+ " cab938-3 | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " username | \n",
+ "
\n",
+ " \n",
+ " brooksch | \n",
+ "
\n",
+ " \n",
+ " cab938-1 | \n",
+ "
\n",
+ " \n",
+ " cab938-2 | \n",
+ "
\n",
+ " \n",
+ " cab938-3 | \n",
+ "
\n",
+ " \n",
+ " suiWcd | \n",
+ "
\n",
+ " \n",
+ " mwrjMG | \n",
+ "
\n",
+ " \n",
+ " viezHE | \n",
+ "
\n",
+ " \n",
+ " ObeIuf | \n",
+ "
\n",
+ " \n",
+ " ZGMSye | \n",
+ "
\n",
+ " \n",
+ " inRgxM | \n",
+ "
\n",
+ " \n",
+ " qJOiQn | \n",
+ "
\n",
+ " \n",
+ " wMaRtb | \n",
+ "
\n",
+ " \n",
+ " sxjXtv | \n",
+ "
\n",
+ " \n",
+ " uJmLWs | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " username | \n",
+ "
\n",
+ " \n",
+ " brooksch | \n",
+ "
\n",
+ " \n",
+ " cab938-1 | \n",
+ "
\n",
+ " \n",
+ " cab938-2 | \n",
+ "
\n",
+ " \n",
+ " cab938-3 | \n",
+ "
\n",
+ " \n",
+ " suiWcd | \n",
+ "
\n",
+ " \n",
+ " mwrjMG | \n",
+ "
\n",
+ " \n",
+ " viezHE | \n",
+ "
\n",
+ " \n",
+ " ObeIuf | \n",
+ "
\n",
+ " \n",
+ " ZGMSye | \n",
+ "
\n",
+ " \n",
+ " inRgxM | \n",
+ "
\n",
+ " \n",
+ " qJOiQn | \n",
+ "
\n",
+ " \n",
+ " wMaRtb | \n",
+ "
\n",
+ " \n",
+ " sxjXtv | \n",
+ "
\n",
+ " \n",
+ " uJmLWs | \n",
+ "
\n",
+ " \n",
+ " wQGICg | \n",
+ "
\n",
+ " \n",
+ " zYBbMX | \n",
+ "
\n",
+ " \n",
+ " zxvgFq | \n",
+ "
\n",
+ " \n",
+ " LfIkWO | \n",
+ "
\n",
+ " \n",
+ " pHVWTY | \n",
+ "
\n",
+ " \n",
+ " dUtuPp | \n",
+ "
\n",
+ " \n",
+ " qzEHWO | \n",
+ "
\n",
+ " \n",
+ " jCKTuv | \n",
+ "
\n",
+ " \n",
+ " pqsUZf | \n",
+ "
\n",
+ " \n",
+ " glIxbE | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " id | \n",
+ " descr | \n",
+ " num_points | \n",
+ "
\n",
+ " \n",
+ " 0 | \n",
+ " sample assignment | \n",
+ " 100 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " sample assignment | \n",
+ " 100 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " sample assignment | \n",
+ " 100 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " sample assignment | \n",
+ " 100 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " sample assignment | \n",
+ " 100 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " sample assignment | \n",
+ " 100 | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " username | \n",
+ "
\n",
+ " \n",
+ " brooksch | \n",
+ "
\n",
+ " \n",
+ " cab938-1 | \n",
+ "
\n",
+ " \n",
+ " cab938-2 | \n",
+ "
\n",
+ " \n",
+ " cab938-3 | \n",
+ "
\n",
+ " \n",
+ " suiWcd | \n",
+ "
\n",
+ " \n",
+ " mwrjMG | \n",
+ "
\n",
+ " \n",
+ " viezHE | \n",
+ "
\n",
+ " \n",
+ " ObeIuf | \n",
+ "
\n",
+ " \n",
+ " ZGMSye | \n",
+ "
\n",
+ " \n",
+ " inRgxM | \n",
+ "
\n",
+ " \n",
+ " qJOiQn | \n",
+ "
\n",
+ " \n",
+ " wMaRtb | \n",
+ "
\n",
+ " \n",
+ " sxjXtv | \n",
+ "
\n",
+ " \n",
+ " uJmLWs | \n",
+ "
\n",
+ " \n",
+ " wQGICg | \n",
+ "
\n",
+ " \n",
+ " zYBbMX | \n",
+ "
\n",
+ " \n",
+ " zxvgFq | \n",
+ "
\n",
+ " \n",
+ " LfIkWO | \n",
+ "
\n",
+ " \n",
+ " pHVWTY | \n",
+ "
\n",
+ " \n",
+ " dUtuPp | \n",
+ "
\n",
+ " \n",
+ " qzEHWO | \n",
+ "
\n",
+ " \n",
+ " jCKTuv | \n",
+ "
\n",
+ " \n",
+ " pqsUZf | \n",
+ "
\n",
+ " \n",
+ " glIxbE | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " timestamp | \n",
+ " user | \n",
+ " assignment | \n",
+ " points_awarded | \n",
+ "
\n",
+ " \n",
+ " 2019-12-02 14:31:24.406072 | \n",
+ " viezHE | \n",
+ " 5 | \n",
+ " 76 | \n",
+ "
\n",
+ " \n",
+ " 2019-12-02 14:31:24.411427 | \n",
+ " qJOiQn | \n",
+ " 0 | \n",
+ " 29 | \n",
+ "
\n",
+ " \n",
+ " 2019-12-02 14:31:24.414247 | \n",
+ " qJOiQn | \n",
+ " 5 | \n",
+ " 88 | \n",
+ "
\n",
+ " \n",
+ " 2019-12-02 14:31:24.416857 | \n",
+ " jCKTuv | \n",
+ " 5 | \n",
+ " 99 | \n",
+ "
\n",
+ " \n",
+ " 2019-12-02 14:31:24.419301 | \n",
+ " cab938-1 | \n",
+ " 0 | \n",
+ " 32 | \n",
+ "
\n",
+ " \n",
+ " 2019-12-02 14:31:24.421968 | \n",
+ " cab938-2 | \n",
+ " 3 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " 2019-12-02 14:31:24.424329 | \n",
+ " viezHE | \n",
+ " 0 | \n",
+ " 17 | \n",
+ "
\n",
+ " \n",
+ " 2019-12-02 14:31:24.426644 | \n",
+ " qzEHWO | \n",
+ " 5 | \n",
+ " 27 | \n",
+ "
\n",
+ " \n",
+ " 2019-12-02 14:31:24.428901 | \n",
+ " pHVWTY | \n",
+ " 1 | \n",
+ " 11 | \n",
+ "
\n",
+ " \n",
+ " 2019-12-02 14:31:24.431243 | \n",
+ " ObeIuf | \n",
+ " 5 | \n",
+ " 61 | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " points_awarded | \n",
+ "
\n",
+ " \n",
+ " 76 | \n",
+ "
\n",
+ " \n",
+ " 29 | \n",
+ "
\n",
+ " \n",
+ " 88 | \n",
+ "
\n",
+ " \n",
+ " 99 | \n",
+ "
\n",
+ " \n",
+ " 32 | \n",
+ "
\n",
+ " \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " 17 | \n",
+ "
\n",
+ " \n",
+ " 27 | \n",
+ "
\n",
+ " \n",
+ " 11 | \n",
+ "
\n",
+ " \n",
+ " 61 | \n",
+ "
\n",
+ " \n",
+ " 38 | \n",
+ "
\n",
+ " \n",
+ " 23 | \n",
+ "
\n",
+ " \n",
+ " 54 | \n",
+ "
\n",
+ " \n",
+ " 90 | \n",
+ "
\n",
+ " \n",
+ " 39 | \n",
+ "
\n",
+ " \n",
+ " 58 | \n",
+ "
\n",
+ " \n",
+ " 100 | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ "
\n",
+ " \n",
+ " 79 | \n",
+ "
\n",
+ " \n",
+ " 14 | \n",
+ "
\n",
+ " \n",
+ " 56 | \n",
+ "
\n",
+ " \n",
+ " 18 | \n",
+ "
\n",
+ " \n",
+ " 22 | \n",
+ "
\n",
+ " \n",
+ " 86 | \n",
+ "
\n",
+ " \n",
+ " 76 | \n",
+ "
\n",
+ " \n",
+ " 91 | \n",
+ "
\n",
+ " \n",
+ " 18 | \n",
+ "
\n",
+ " \n",
+ " 28 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ "
\n",
+ " \n",
+ " 68 | \n",
+ "
\n",
+ " \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " 53 | \n",
+ "
\n",
+ " \n",
+ " 50 | \n",
+ "
\n",
+ " \n",
+ " 15 | \n",
+ "
\n",
+ " \n",
+ " 67 | \n",
+ "
\n",
+ " \n",
+ " 33 | \n",
+ "
\n",
+ " \n",
+ " 74 | \n",
+ "
\n",
+ " \n",
+ " 22 | \n",
+ "
\n",
+ " \n",
+ " 68 | \n",
+ "
\n",
+ " \n",
+ " 90 | \n",
+ "
\n",
+ " \n",
+ " 44 | \n",
+ "
\n",
+ " \n",
+ " 75 | \n",
+ "
\n",
+ " \n",
+ " 68 | \n",
+ "
\n",
+ " \n",
+ " 27 | \n",
+ "
\n",
+ " \n",
+ " 83 | \n",
+ "
\n",
+ " \n",
+ " 67 | \n",
+ "
\n",
+ " \n",
+ " 58 | \n",
+ "
\n",
+ " \n",
+ " 16 | \n",
+ "
\n",
+ " \n",
+ " 72 | \n",
+ "
\n",
+ " \n",
+ " 86 | \n",
+ "
\n",
+ " \n",
+ " 95 | \n",
+ "
\n",
+ " \n",
+ " 57 | \n",
+ "
\n",
+ " \n",
+ " 11 | \n",
+ "
\n",
+ " \n",
+ " 49 | \n",
+ "
\n",
+ " \n",
+ " 74 | \n",
+ "
\n",
+ " \n",
+ " 32 | \n",
+ "
\n",
+ " \n",
+ " 52 | \n",
+ "
\n",
+ " \n",
+ " 56 | \n",
+ "
\n",
+ " \n",
+ " 26 | \n",
+ "
\n",
+ " \n",
+ " 60 | \n",
+ "
\n",
+ " \n",
+ " 50 | \n",
+ "
\n",
+ " \n",
+ " 41 | \n",
+ "
\n",
+ " \n",
+ " 94 | \n",
+ "
\n",
+ " \n",
+ " 30 | \n",
+ "
\n",
+ " \n",
+ " 96 | \n",
+ "
\n",
+ " \n",
+ " 82 | \n",
+ "
\n",
+ " \n",
+ " 24 | \n",
+ "
\n",
+ " \n",
+ " 80 | \n",
+ "
\n",
+ " \n",
+ " 99 | \n",
+ "
\n",
+ " \n",
+ " 23 | \n",
+ "
\n",
+ " \n",
+ " 69 | \n",
+ "
\n",
+ " \n",
+ " 91 | \n",
+ "
\n",
+ " \n",
+ " 29 | \n",
+ "
\n",
+ " \n",
+ " 46 | \n",
+ "
\n",
+ " \n",
+ " 40 | \n",
+ "
\n",
+ " \n",
+ " 79 | \n",
+ "
\n",
+ " \n",
+ " 62 | \n",
+ "
\n",
+ " \n",
+ " 41 | \n",
+ "
\n",
+ " \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ " 68 | \n",
+ "
\n",
+ " \n",
+ " 52 | \n",
+ "
\n",
+ " \n",
+ " 46 | \n",
+ "
\n",
+ " \n",
+ " 92 | \n",
+ "
\n",
+ " \n",
+ " 40 | \n",
+ "
\n",
+ " \n",
+ " 25 | \n",
+ "
\n",
+ " \n",
+ " 74 | \n",
+ "
\n",
+ " \n",
+ " 83 | \n",
+ "
\n",
+ " \n",
+ " 40 | \n",
+ "
\n",
+ " \n",
+ " 21 | \n",
+ "
\n",
+ " \n",
+ " 75 | \n",
+ "
\n",
+ " \n",
+ " 22 | \n",
+ "
\n",
+ " \n",
+ " 26 | \n",
+ "
\n",
+ " \n",
+ " 47 | \n",
+ "
\n",
+ " \n",
+ " 35 | \n",
+ "
\n",
+ " \n",
+ " 85 | \n",
+ "
\n",
+ " \n",
+ " 86 | \n",
+ "
\n",
+ " \n",
+ " 25 | \n",
+ "
\n",
+ " \n",
+ " 69 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " 43 | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " max | \n",
+ "
\n",
+ " \n",
+ " 100 | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " max_column | \n",
+ " bluebird | \n",
+ " mean | \n",
+ "
\n",
+ " \n",
+ " 100 | \n",
+ " 0 | \n",
+ " 51.3800000000000000 | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " stddev | \n",
+ " count | \n",
+ "
\n",
+ " \n",
+ " 27.8044324640238727 | \n",
+ " 100 | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " user | \n",
+ " average | \n",
+ "
\n",
+ " \n",
+ " jovyan | \n",
+ " 51.3800000000000000 | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " timestamp | \n",
+ " user | \n",
+ " assignment | \n",
+ " points_awarded | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 2019-12-02 14:31:24.406072 | \n",
+ " viezHE | \n",
+ " 5 | \n",
+ " 76 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 2019-12-02 14:31:24.411427 | \n",
+ " qJOiQn | \n",
+ " 0 | \n",
+ " 29 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 2019-12-02 14:31:24.414247 | \n",
+ " qJOiQn | \n",
+ " 5 | \n",
+ " 88 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 2019-12-02 14:31:24.416857 | \n",
+ " jCKTuv | \n",
+ " 5 | \n",
+ " 99 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 2019-12-02 14:31:24.419301 | \n",
+ " cab938-1 | \n",
+ " 0 | \n",
+ " 32 | \n",
+ "
\n",
+ " \n",
+ "
\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",
+ " points_awarded | \n",
+ "
\n",
+ " \n",
+ " user | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " LfIkWO | \n",
+ " 60.200000 | \n",
+ "
\n",
+ " \n",
+ " ObeIuf | \n",
+ " 40.285714 | \n",
+ "
\n",
+ " \n",
+ " brooksch | \n",
+ " 37.750000 | \n",
+ "
\n",
+ " \n",
+ " cab938-1 | \n",
+ " 67.333333 | \n",
+ "
\n",
+ " \n",
+ " cab938-2 | \n",
+ " 25.333333 | \n",
+ "
\n",
+ " \n",
+ " cab938-3 | \n",
+ " 63.500000 | \n",
+ "
\n",
+ " \n",
+ " dUtuPp | \n",
+ " 22.000000 | \n",
+ "
\n",
+ " \n",
+ " glIxbE | \n",
+ " 13.000000 | \n",
+ "
\n",
+ " \n",
+ " inRgxM | \n",
+ " 34.400000 | \n",
+ "
\n",
+ " \n",
+ " jCKTuv | \n",
+ " 61.400000 | \n",
+ "
\n",
+ " \n",
+ " mwrjMG | \n",
+ " 78.000000 | \n",
+ "
\n",
+ " \n",
+ " pHVWTY | \n",
+ " 43.875000 | \n",
+ "
\n",
+ " \n",
+ " pqsUZf | \n",
+ " 54.250000 | \n",
+ "
\n",
+ " \n",
+ " qJOiQn | \n",
+ " 50.600000 | \n",
+ "
\n",
+ " \n",
+ " qzEHWO | \n",
+ " 47.600000 | \n",
+ "
\n",
+ " \n",
+ " suiWcd | \n",
+ " 65.166667 | \n",
+ "
\n",
+ " \n",
+ " sxjXtv | \n",
+ " 48.625000 | \n",
+ "
\n",
+ " \n",
+ " viezHE | \n",
+ " 59.416667 | \n",
+ "
\n",
+ " \n",
+ " wMaRtb | \n",
+ " 54.500000 | \n",
+ "
\n",
+ " \n",
+ " wQGICg | \n",
+ " 69.000000 | \n",
+ "
\n",
+ " \n",
+ " zYBbMX | \n",
+ " 74.000000 | \n",
+ "
\n",
+ " \n",
+ " zxvgFq | \n",
+ " 67.666667 | \n",
+ "
\n",
+ " \n",
+ "
\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",
+ " user | \n",
+ " avg | \n",
+ "
\n",
+ " \n",
+ " jCKTuv | \n",
+ " 61.4000000000000000 | \n",
+ "
\n",
+ " \n",
+ " pqsUZf | \n",
+ " 54.2500000000000000 | \n",
+ "
\n",
+ " \n",
+ " qzEHWO | \n",
+ " 47.6000000000000000 | \n",
+ "
\n",
+ " \n",
+ " sxjXtv | \n",
+ " 48.6250000000000000 | \n",
+ "
\n",
+ " \n",
+ " cab938-1 | \n",
+ " 67.3333333333333333 | \n",
+ "
\n",
+ " \n",
+ " viezHE | \n",
+ " 59.4166666666666667 | \n",
+ "
\n",
+ " \n",
+ " brooksch | \n",
+ " 37.7500000000000000 | \n",
+ "
\n",
+ " \n",
+ " wQGICg | \n",
+ " 69.0000000000000000 | \n",
+ "
\n",
+ " \n",
+ " wMaRtb | \n",
+ " 54.5000000000000000 | \n",
+ "
\n",
+ " \n",
+ " glIxbE | \n",
+ " 13.0000000000000000 | \n",
+ "
\n",
+ " \n",
+ " cab938-3 | \n",
+ " 63.5000000000000000 | \n",
+ "
\n",
+ " \n",
+ " LfIkWO | \n",
+ " 60.2000000000000000 | \n",
+ "
\n",
+ " \n",
+ " zxvgFq | \n",
+ " 67.6666666666666667 | \n",
+ "
\n",
+ " \n",
+ " inRgxM | \n",
+ " 34.4000000000000000 | \n",
+ "
\n",
+ " \n",
+ " dUtuPp | \n",
+ " 22.0000000000000000 | \n",
+ "
\n",
+ " \n",
+ " qJOiQn | \n",
+ " 50.6000000000000000 | \n",
+ "
\n",
+ " \n",
+ " cab938-2 | \n",
+ " 25.3333333333333333 | \n",
+ "
\n",
+ " \n",
+ " mwrjMG | \n",
+ " 78.0000000000000000 | \n",
+ "
\n",
+ " \n",
+ " ObeIuf | \n",
+ " 40.2857142857142857 | \n",
+ "
\n",
+ " \n",
+ " zYBbMX | \n",
+ " 74.0000000000000000 | \n",
+ "
\n",
+ " \n",
+ " pHVWTY | \n",
+ " 43.8750000000000000 | \n",
+ "
\n",
+ " \n",
+ " suiWcd | \n",
+ " 65.1666666666666667 | \n",
+ "
\n",
+ "
"
+ ],
+ "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",
+ " id | \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ "[]"
+ ]
+ },
+ "execution_count": 56,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "%sql select * from questions"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,