diff --git a/Lectures/Lecture4/PandasAndSQL.ipynb b/Lectures/Lecture4/PandasAndSQL.ipynb index be2c58a..dae4aa6 100644 --- a/Lectures/Lecture4/PandasAndSQL.ipynb +++ b/Lectures/Lecture4/PandasAndSQL.ipynb @@ -202,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -384,7 +384,7 @@ "16 41 Fred Thompson D. R" ] }, - "execution_count": 99, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -1008,7 +1008,15 @@ "metadata": { "collapsed": false }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "bash: line 2: sqlite3: command not found\n" + ] + } + ], "source": [ "%%bash\n", "tail -n +2 candidates.txt > candidates_nohead.txt\n", @@ -1025,23 +1033,7 @@ { "data": { "text/plain": [ - "[(16, u'Mike', u'Huckabee', u'', u'R'),\n", - " (20, u'Barack', u'Obama', u'', u'D'),\n", - " (22, u'Rudolph', u'Giuliani', u'', u'R'),\n", - " (24, u'Mike', u'Gravel', u'', u'D'),\n", - " (26, u'John', u'Edwards', u'', u'D'),\n", - " (29, u'Bill', u'Richardson', u'', u'D'),\n", - " (30, u'Duncan', u'Hunter', u'', u'R'),\n", - " (31, u'Dennis', u'Kucinich', u'', u'D'),\n", - " (32, u'Ron', u'Paul', u'', u'R'),\n", - " (33, u'Joseph', u'Biden', u'', u'D'),\n", - " (34, u'Hillary', u'Clinton', u'R.', u'D'),\n", - " (35, u'Mitt', u'Romney', u'', u'R'),\n", - " (36, u'Samuel', u'Brownback', u'', u'R'),\n", - " (37, u'John', u'McCain', u'', u'R'),\n", - " (38, u'Tom', u'Tancredo', u'', u'R'),\n", - " (39, u'Christopher', u'Dodd', u'J.', u'D'),\n", - " (41, u'Fred', u'Thompson', u'D.', u'R')]" + "[]" ] }, "execution_count": 21, @@ -1531,7 +1523,7 @@ }, { "cell_type": "code", - "execution_count": 145, + "execution_count": 27, "metadata": { "collapsed": false }, @@ -1540,7 +1532,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[(28, u'Buckheit', u'Bruce', None, u'8904 KAREN DR', None, u'FAIRFAX', u'VA', u'220312731', 100, u'2007-09-19', 20, u'junk'), (78, u'Ranganath', u'Anoop', None, u'2507 Willard Drive', None, u'Charlottesville', u'VA', u'22903', -100, u'2008-04-21', 32, u'junk'), (89, u'Perreault', u'Louise', None, u'503 Brockridge Hunt Drive', None, u'Hampton', u'VA', u'23666', -34.08, u'2008-04-21', 32, u'junk'), (146, u'ABDELLA', u'THOMAS', u'M.', u'4231 MONUMENT WALL WAY #340', None, u'FAIRFAX', u'VA', u'220308440', 50, u'2007-09-30', 35, u'junk')]\n" + "[(28, u'Buckheit', u'Bruce', None, u'8904 KAREN DR', None, u'FAIRFAX', u'VA', u'220312731', 100, u'2007-09-19', 20), (78, u'Ranganath', u'Anoop', None, u'2507 Willard Drive', None, u'Charlottesville', u'VA', u'22903', -100, u'2008-04-21', 32), (89, u'Perreault', u'Louise', None, u'503 Brockridge Hunt Drive', None, u'Hampton', u'VA', u'23666', -34.08, u'2008-04-21', 32), (146, u'ABDELLA', u'THOMAS', u'M.', u'4231 MONUMENT WALL WAY #340', None, u'FAIRFAX', u'VA', u'220308440', 50, u'2007-09-30', 35)]\n" ] }, { @@ -1638,7 +1630,7 @@ "3 146 ABDELLA THOMAS M. 4231 MONUMENT WALL WAY #340 None FAIRFAX VA 220308440 50.00 2007-09-30 35" ] }, - "execution_count": 145, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } @@ -3756,70 +3748,70 @@ " \n", " \n", " 0\n", - " Agee\n", - " Steven\n", + " AARONS\n", + " CHARLES\n", " \n", " \n", " 1\n", - " Ahrens\n", - " Don\n", + " ABACHERLI\n", + " SHIRLEY\n", " \n", " \n", " 2\n", - " Akin\n", - " Charles\n", + " ABAIR\n", + " PETER\n", " \n", " \n", " 3\n", - " Akin\n", - " Mike\n", + " ABATE\n", + " MARIA\n", " \n", " \n", " 4\n", - " Akin\n", - " Rebecca\n", + " ABBO\n", + " PAULINE\n", " \n", " \n", " 5\n", - " Aldridge\n", - " Brittni\n", + " ABBOT\n", + " DAVID\n", " \n", " \n", " 6\n", - " Allen\n", - " John D.\n", + " ABBOTT\n", + " GERALD\n", " \n", " \n", " 7\n", - " Allison\n", - " John W.\n", + " ABBOTT\n", + " MIKE\n", " \n", " \n", " 8\n", - " Allison\n", - " Rebecca\n", + " ABBOTT\n", + " ROBERT\n", " \n", " \n", " 9\n", - " Altes\n", - " R.D.\n", + " ABBOTT\n", + " RONALD\n", " \n", " \n", "\n", "" ], "text/plain": [ - " last_name first_name\n", - "0 Agee Steven\n", - "1 Ahrens Don\n", - "2 Akin Charles\n", - "3 Akin Mike\n", - "4 Akin Rebecca\n", - "5 Aldridge Brittni\n", - "6 Allen John D.\n", - "7 Allison John W.\n", - "8 Allison Rebecca\n", - "9 Altes R.D." + " last_name first_name\n", + "0 AARONS CHARLES\n", + "1 ABACHERLI SHIRLEY\n", + "2 ABAIR PETER\n", + "3 ABATE MARIA\n", + "4 ABBO PAULINE\n", + "5 ABBOT DAVID\n", + "6 ABBOTT GERALD\n", + "7 ABBOTT MIKE\n", + "8 ABBOTT ROBERT\n", + "9 ABBOTT RONALD" ] }, "execution_count": 45, @@ -4585,7 +4577,7 @@ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 52, @@ -5082,7 +5074,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 58, "metadata": { "collapsed": false }, @@ -5095,7 +5087,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 59, "metadata": { "collapsed": false }, @@ -5217,7 +5209,7 @@ "4 146 ABDELLA THOMAS M. 4231 MONUMENT WALL WAY #340 None FAIRFAX VA 220308440 50.00 2007-09-30 35 junk" ] }, - "execution_count": 62, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -5238,7 +5230,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 60, "metadata": { "collapsed": false }, @@ -5248,10 +5240,10 @@ "evalue": "near \"DROP\": syntax error", "output_type": "error", "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mOperationalError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0malt\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"ALTER TABLE contributors DROP COLUMN name;\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mdb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcursor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0malt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mdb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcommit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mOperationalError\u001b[0m: near \"DROP\": syntax error" + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mOperationalError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0malt\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"ALTER TABLE contributors DROP COLUMN name;\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mdb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcursor\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0malt\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[0mdb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mOperationalError\u001b[0m: near \"DROP\": syntax error" ] } ], @@ -5270,7 +5262,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 61, "metadata": { "collapsed": false }, @@ -5288,7 +5280,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 62, "metadata": { "collapsed": false }, @@ -5371,7 +5363,7 @@ "max 9.951532e+08 4600.000000 37.000000" ] }, - "execution_count": 66, + "execution_count": 62, "metadata": {}, "output_type": "execute_result" } @@ -5382,7 +5374,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 63, "metadata": { "collapsed": false }, @@ -5393,7 +5385,7 @@ "4600.0" ] }, - "execution_count": 67, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } @@ -5404,7 +5396,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 64, "metadata": { "collapsed": false }, @@ -5454,7 +5446,7 @@ "30 Buckel Linda NaN PO Box 683130 NaN Park City UT 840683130 4600 2007-08-14 20" ] }, - "execution_count": 68, + "execution_count": 64, "metadata": {}, "output_type": "execute_result" } @@ -5465,7 +5457,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 65, "metadata": { "collapsed": false }, @@ -5474,7 +5466,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[(31, u'Buckel', u'Linda', None, u'PO Box 683130', None, u'Park City', u'UT', u'840683130', 4600, u'2007-08-14', 20, u'Buckel, Linda', 4600)]\n" + "[(175, u'ABRAHAM', u'SALEM', u'A.', u'P.O. BOX 7', None, u'CANADIAN', u'TX', u'790140007', 1300, u'2008-01-30', 37, u'ABRAHAM, SALEM', 4600)]\n" ] }, { @@ -5503,30 +5495,30 @@ " \n", " \n", " 0\n", - " 31\n", - " Buckel\n", - " Linda\n", - " None\n", - " PO Box 683130\n", + " 175\n", + " ABRAHAM\n", + " SALEM\n", + " A.\n", + " P.O. BOX 7\n", " None\n", - " Park City\n", - " UT\n", - " 840683130\n", - " 4600\n", - " 2007-08-14\n", - " 20\n", - " Buckel, Linda\n", + " CANADIAN\n", + " TX\n", + " 790140007\n", + " 1300\n", + " 2008-01-30\n", + " 37\n", + " ABRAHAM, SALEM\n", " \n", " \n", "\n", "" ], "text/plain": [ - " id last_name first_name middle_name street_1 street_2 city state zip amount date candidate_id maxamt\n", - "0 31 Buckel Linda None PO Box 683130 None Park City UT 840683130 4600 2007-08-14 20 Buckel, Linda" + " id last_name first_name middle_name street_1 street_2 city state zip amount date candidate_id maxamt\n", + "0 175 ABRAHAM SALEM A. P.O. BOX 7 None CANADIAN TX 790140007 1300 2008-01-30 37 ABRAHAM, SALEM" ] }, - "execution_count": 69, + "execution_count": 65, "metadata": {}, "output_type": "execute_result" } @@ -5539,7 +5531,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 66, "metadata": { "collapsed": false }, @@ -5559,7 +5551,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 67, "metadata": { "collapsed": false }, @@ -5579,7 +5571,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 68, "metadata": { "collapsed": false }, @@ -5644,7 +5636,7 @@ "159 ABATE MARIA ELENA 1291 NIGHTINGALE AVENUE NaN MIAMI SPRINGS FL 331663832 2600 2008-01-25 37" ] }, - "execution_count": 72, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -5655,7 +5647,7 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 69, "metadata": { "collapsed": false }, @@ -5723,7 +5715,7 @@ "1 160 ABATE MARIA ELENA 1291 NIGHTINGALE AVENUE None MIAMI SPRINGS FL 331663832 2600 2008-01-25 37" ] }, - "execution_count": 73, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } @@ -5749,7 +5741,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 70, "metadata": { "collapsed": false }, @@ -6028,7 +6020,7 @@ "WA 2941290251 -500.00 90" ] }, - "execution_count": 74, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } @@ -6039,7 +6031,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 71, "metadata": { "collapsed": false }, @@ -6086,7 +6078,7 @@ "Name: amount, dtype: float64" ] }, - "execution_count": 75, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } @@ -6097,7 +6089,7 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 72, "metadata": { "collapsed": false }, @@ -6111,7 +6103,7 @@ " 'AK', 'LA', 'AZ'], dtype=object)" ] }, - "execution_count": 76, + "execution_count": 72, "metadata": {}, "output_type": "execute_result" } @@ -6122,7 +6114,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 73, "metadata": { "collapsed": false }, @@ -6364,7 +6356,7 @@ "35 WA -500.00" ] }, - "execution_count": 77, + "execution_count": 73, "metadata": {}, "output_type": "execute_result" } @@ -6383,7 +6375,7 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 74, "metadata": { "collapsed": false }, @@ -6493,7 +6485,7 @@ "4 Akin Charles NaN 10187 Sugar Creek Road NaN Bentonville AR 72712 100 2007-06-16 16" ] }, - "execution_count": 78, + "execution_count": 74, "metadata": {}, "output_type": "execute_result" } @@ -6511,7 +6503,7 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 75, "metadata": { "collapsed": false }, @@ -6629,7 +6621,7 @@ "Akin Charles NaN 10187 Sugar Creek Road NaN Bentonville AR 72712 100 2007-06-16 16" ] }, - "execution_count": 80, + "execution_count": 75, "metadata": {}, "output_type": "execute_result" } @@ -6642,7 +6634,7 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 76, "metadata": { "collapsed": false }, @@ -6760,7 +6752,7 @@ "Aldridge Brittni NaN 808 Capitol Square Place, SW NaN Washington DC 20024 250 2007-06-06 16" ] }, - "execution_count": 81, + "execution_count": 76, "metadata": {}, "output_type": "execute_result" }