|
@@ -18,23 +18,22 @@
|
|
|
"name": "stdout",
|
|
|
"output_type": "stream",
|
|
|
"text": [
|
|
|
- "(0, 'id', 'integer', 0, None, 1)\n",
|
|
|
- "(1, 'category', 'text', 0, None, 0)\n",
|
|
|
- "(2, 'nominee', 'text', 0, None, 0)\n",
|
|
|
- "(3, 'movie', 'text', 0, None, 0)\n",
|
|
|
- "(4, 'character', 'text', 0, None, 0)\n",
|
|
|
- "(5, 'won', 'text', 0, None, 0)\n",
|
|
|
- "(6, 'ceremony_id', 'integer', 0, None, 0)\n",
|
|
|
- "(1, 'Actor -- Leading Role', 'Javier Bardem', 'Biutiful', 'Uxbal', '0', 1)\n",
|
|
|
- "(2, 'Actor -- Leading Role', 'Jeff Bridges', 'True Grit', 'Rooster Cogburn', '0', 1)\n",
|
|
|
- "(3, 'Actor -- Leading Role', 'Jesse Eisenberg', 'The Social Network', 'Mark Zuckerberg', '0', 1)\n",
|
|
|
- "(4, 'Actor -- Leading Role', 'Colin Firth', \"The King's Speech\", 'King George VI', '1', 1)\n",
|
|
|
- "(5, 'Actor -- Leading Role', 'James Franco', '127 Hours', 'Aron Ralston', '0', 1)\n",
|
|
|
- "(6, 'Actor -- Supporting Role', 'Christian Bale', 'The Fighter', 'Dicky Eklund', '1', 1)\n",
|
|
|
- "(7, 'Actor -- Supporting Role', 'John Hawkes', \"Winter's Bone\", 'Teardrop', '0', 1)\n",
|
|
|
- "(8, 'Actor -- Supporting Role', 'Jeremy Renner', 'The Town', 'James Coughlin', '0', 1)\n",
|
|
|
- "(9, 'Actor -- Supporting Role', 'Mark Ruffalo', 'The Kids Are All Right', 'Paul', '0', 1)\n",
|
|
|
- "(10, 'Actor -- Supporting Role', 'Geoffrey Rush', \"The King's Speech\", 'Lionel Logue', '0', 1)\n"
|
|
|
+ "(0, 'Year', 'INTEGER', 0, None, 0)\n",
|
|
|
+ "(1, 'Category', 'TEXT', 0, None, 0)\n",
|
|
|
+ "(2, 'Nominee', 'TEXT', 0, None, 0)\n",
|
|
|
+ "(3, 'Won', 'INTEGER', 0, None, 0)\n",
|
|
|
+ "(4, 'Movie', 'TEXT', 0, None, 0)\n",
|
|
|
+ "(5, 'Character', 'TEXT', 0, None, 0)\n",
|
|
|
+ "(2010, 'Actor -- Leading Role', 'Javier Bardem', 0, 'Biutiful', 'Uxbal')\n",
|
|
|
+ "(2010, 'Actor -- Leading Role', 'Jeff Bridges', 0, 'True Grit', 'Rooster Cogburn')\n",
|
|
|
+ "(2010, 'Actor -- Leading Role', 'Jesse Eisenberg', 0, 'The Social Network', 'Mark Zuckerberg')\n",
|
|
|
+ "(2010, 'Actor -- Leading Role', 'Colin Firth', 1, \"The King's Speech\", 'King George VI')\n",
|
|
|
+ "(2010, 'Actor -- Leading Role', 'James Franco', 0, '127 Hours', 'Aron Ralston')\n",
|
|
|
+ "(2010, 'Actor -- Supporting Role', 'Christian Bale', 1, 'The Fighter', 'Dicky Eklund')\n",
|
|
|
+ "(2010, 'Actor -- Supporting Role', 'John Hawkes', 0, \"Winter's Bone\", 'Teardrop')\n",
|
|
|
+ "(2010, 'Actor -- Supporting Role', 'Jeremy Renner', 0, 'The Town', 'James Coughlin')\n",
|
|
|
+ "(2010, 'Actor -- Supporting Role', 'Mark Ruffalo', 0, 'The Kids Are All Right', 'Paul')\n",
|
|
|
+ "(2010, 'Actor -- Supporting Role', 'Geoffrey Rush', 0, \"The King's Speech\", 'Lionel Logue')\n"
|
|
|
]
|
|
|
}
|
|
|
],
|
|
@@ -66,14 +65,11 @@
|
|
|
},
|
|
|
"outputs": [
|
|
|
{
|
|
|
- "ename": "OperationalError",
|
|
|
- "evalue": "table ceremonies already exists",
|
|
|
- "output_type": "error",
|
|
|
- "traceback": [
|
|
|
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
|
|
- "\u001b[0;31mOperationalError\u001b[0m Traceback (most recent call last)",
|
|
|
- "\u001b[0;32m<ipython-input-2-bfea1ef9962a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 12\u001b[0m ]\n\u001b[1;32m 13\u001b[0m \u001b[0mcreate_ceremonies\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"create table ceremonies (id integer primary key, year integer, host text);\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 14\u001b[0;31m \u001b[0mconn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcreate_ceremonies\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 15\u001b[0m \u001b[0minsert_query\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"insert into ceremonies (Year, Host) values (?,?);\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0mconn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecutemany\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minsert_query\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0myears_hosts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
|
- "\u001b[0;31mOperationalError\u001b[0m: table ceremonies already exists"
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "[(1, 2010, 'Steve Martin'), (2, 2009, 'Hugh Jackman'), (3, 2008, 'Jon Stewart'), (4, 2007, 'Ellen DeGeneres'), (5, 2006, 'Jon Stewart'), (6, 2005, 'Chris Rock'), (7, 2004, 'Billy Crystal'), (8, 2003, 'Steve Martin'), (9, 2002, 'Whoopi Goldberg'), (10, 2001, 'Steve Martin')]\n",
|
|
|
+ "[(0, 'id', 'integer', 0, None, 1), (1, 'year', 'integer', 0, None, 0), (2, 'host', 'text', 0, None, 0)]\n"
|
|
|
]
|
|
|
}
|
|
|
],
|
|
@@ -108,11 +104,22 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 3,
|
|
|
"metadata": {
|
|
|
"collapsed": false
|
|
|
},
|
|
|
- "outputs": [],
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "text/plain": [
|
|
|
+ "<sqlite3.Cursor at 0x10675e3b0>"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "execution_count": 3,
|
|
|
+ "metadata": {},
|
|
|
+ "output_type": "execute_result"
|
|
|
+ }
|
|
|
+ ],
|
|
|
"source": [
|
|
|
"conn.execute(\"PRAGMA foreign_keys = ON;\")"
|
|
|
]
|
|
@@ -126,11 +133,19 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 4,
|
|
|
"metadata": {
|
|
|
"collapsed": false
|
|
|
},
|
|
|
- "outputs": [],
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "[(1, 'Actor -- Leading Role', 'Javier Bardem', 'Biutiful', 'Uxbal', '0', 1), (2, 'Actor -- Leading Role', 'Jeff Bridges', 'True Grit', 'Rooster Cogburn', '0', 1), (3, 'Actor -- Leading Role', 'Jesse Eisenberg', 'The Social Network', 'Mark Zuckerberg', '0', 1), (4, 'Actor -- Leading Role', 'Colin Firth', \"The King's Speech\", 'King George VI', '1', 1), (5, 'Actor -- Leading Role', 'James Franco', '127 Hours', 'Aron Ralston', '0', 1)]\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
"source": [
|
|
|
"create_nominations_two = '''create table nominations_two \n",
|
|
|
"(id integer primary key, \n",
|
|
@@ -173,11 +188,22 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 5,
|
|
|
"metadata": {
|
|
|
"collapsed": false
|
|
|
},
|
|
|
- "outputs": [],
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "text/plain": [
|
|
|
+ "<sqlite3.Cursor at 0x10675e6c0>"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "execution_count": 5,
|
|
|
+ "metadata": {},
|
|
|
+ "output_type": "execute_result"
|
|
|
+ }
|
|
|
+ ],
|
|
|
"source": [
|
|
|
"drop_nominations = \"drop table nominations;\"\n",
|
|
|
"conn.execute(drop_nominations)\n",
|
|
@@ -195,11 +221,22 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 6,
|
|
|
"metadata": {
|
|
|
"collapsed": false
|
|
|
},
|
|
|
- "outputs": [],
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "data": {
|
|
|
+ "text/plain": [
|
|
|
+ "<sqlite3.Cursor at 0x10675e960>"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ "execution_count": 6,
|
|
|
+ "metadata": {},
|
|
|
+ "output_type": "execute_result"
|
|
|
+ }
|
|
|
+ ],
|
|
|
"source": [
|
|
|
"create_movies = \"create table movies (id integer primary key,movie text);\"\n",
|
|
|
"create_actors = \"create table actors (id integer primary key,actor text);\"\n",
|
|
@@ -220,11 +257,20 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 7,
|
|
|
"metadata": {
|
|
|
"collapsed": false
|
|
|
},
|
|
|
- "outputs": [],
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "[(1, 'Biutiful'), (2, 'True Grit'), (3, 'The Social Network'), (4, \"The King's Speech\"), (5, '127 Hours')]\n",
|
|
|
+ "[(1, 'Javier Bardem'), (2, 'Jeff Bridges'), (3, 'Jesse Eisenberg'), (4, 'Colin Firth'), (5, 'James Franco')]\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
"source": [
|
|
|
"insert_movies = \"insert into movies (movie) select distinct movie from nominations;\"\n",
|
|
|
"insert_actors = \"insert into actors (actor) select distinct nominee from nominations;\"\n",
|
|
@@ -244,11 +290,19 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 8,
|
|
|
"metadata": {
|
|
|
"collapsed": false
|
|
|
},
|
|
|
- "outputs": [],
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "[(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5)]\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
"source": [
|
|
|
"pairs_query = \"select movie,nominee from nominations;\"\n",
|
|
|
"movie_actor_pairs = conn.execute(pairs_query).fetchall()\n",
|