diff --git a/f22/andy_lec_notes/lec29_Nov16_Web1/CS220_Lec29_Sec004_Solution.ipynb b/f22/andy_lec_notes/lec29_Nov16_Web1/CS220_Lec29_Sec004_Solution.ipynb deleted file mode 100644 index 11b017bb6e188bbe2c7c17818ef9a9b4b7a05aa2..0000000000000000000000000000000000000000 --- a/f22/andy_lec_notes/lec29_Nov16_Web1/CS220_Lec29_Sec004_Solution.ipynb +++ /dev/null @@ -1,2660 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "import requests # We will learn about this today!\n", - "import json\n", - "import pandas as pd\n", - "from pandas import Series, DataFrame" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>Title</th>\n", - " <th>Genre</th>\n", - " <th>Director</th>\n", - " <th>Cast</th>\n", - " <th>Year</th>\n", - " <th>Runtime</th>\n", - " <th>Rating</th>\n", - " <th>Revenue</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>Guardians of the Galaxy</td>\n", - " <td>Action,Adventure,Sci-Fi</td>\n", - " <td>James Gunn</td>\n", - " <td>Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...</td>\n", - " <td>2014</td>\n", - " <td>121</td>\n", - " <td>8.1</td>\n", - " <td>333.13</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>Prometheus</td>\n", - " <td>Adventure,Mystery,Sci-Fi</td>\n", - " <td>Ridley Scott</td>\n", - " <td>Noomi Rapace, Logan Marshall-Green, Michael ...</td>\n", - " <td>2012</td>\n", - " <td>124</td>\n", - " <td>7.0</td>\n", - " <td>126.46M</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>Split</td>\n", - " <td>Horror,Thriller</td>\n", - " <td>M. Night Shyamalan</td>\n", - " <td>James McAvoy, Anya Taylor-Joy, Haley Lu Richar...</td>\n", - " <td>2016</td>\n", - " <td>117</td>\n", - " <td>7.3</td>\n", - " <td>138.12M</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>Sing</td>\n", - " <td>Animation,Comedy,Family</td>\n", - " <td>Christophe Lourdelet</td>\n", - " <td>Matthew McConaughey,Reese Witherspoon, Seth Ma...</td>\n", - " <td>2016</td>\n", - " <td>108</td>\n", - " <td>7.2</td>\n", - " <td>270.32</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>Suicide Squad</td>\n", - " <td>Action,Adventure,Fantasy</td>\n", - " <td>David Ayer</td>\n", - " <td>Will Smith, Jared Leto, Margot Robbie, Viola D...</td>\n", - " <td>2016</td>\n", - " <td>123</td>\n", - " <td>6.2</td>\n", - " <td>325.02</td>\n", - " </tr>\n", - " <tr>\n", - " <th>...</th>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1063</th>\n", - " <td>Guardians of the Galaxy Vol. 2</td>\n", - " <td>Action, Adventure, Comedy</td>\n", - " <td>James Gunn</td>\n", - " <td>Chris Pratt, Zoe Saldana, Dave Bautista, Vin D...</td>\n", - " <td>2017</td>\n", - " <td>136</td>\n", - " <td>7.6</td>\n", - " <td>389.81</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1064</th>\n", - " <td>Baby Driver</td>\n", - " <td>Action, Crime, Drama</td>\n", - " <td>Edgar Wright</td>\n", - " <td>Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon...</td>\n", - " <td>2017</td>\n", - " <td>113</td>\n", - " <td>7.6</td>\n", - " <td>107.83</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1065</th>\n", - " <td>Only the Brave</td>\n", - " <td>Action, Biography, Drama</td>\n", - " <td>Joseph Kosinski</td>\n", - " <td>Josh Brolin, Miles Teller, Jeff Bridges, Jenni...</td>\n", - " <td>2017</td>\n", - " <td>134</td>\n", - " <td>7.6</td>\n", - " <td>18.34</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1066</th>\n", - " <td>Incredibles 2</td>\n", - " <td>Animation, Action, Adventure</td>\n", - " <td>Brad Bird</td>\n", - " <td>Craig T. Nelson, Holly Hunter, Sarah Vowell, H...</td>\n", - " <td>2018</td>\n", - " <td>118</td>\n", - " <td>7.6</td>\n", - " <td>608.58</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1067</th>\n", - " <td>A Star Is Born</td>\n", - " <td>Drama, Music, Romance</td>\n", - " <td>Bradley Cooper</td>\n", - " <td>Lady Gaga, Bradley Cooper, Sam Elliott, Greg G...</td>\n", - " <td>2018</td>\n", - " <td>136</td>\n", - " <td>7.6</td>\n", - " <td>215.29</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "<p>1068 rows × 8 columns</p>\n", - "</div>" - ], - "text/plain": [ - " Title Genre \\\n", - "0 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", - "1 Prometheus Adventure,Mystery,Sci-Fi \n", - "2 Split Horror,Thriller \n", - "3 Sing Animation,Comedy,Family \n", - "4 Suicide Squad Action,Adventure,Fantasy \n", - "... ... ... \n", - "1063 Guardians of the Galaxy Vol. 2 Action, Adventure, Comedy \n", - "1064 Baby Driver Action, Crime, Drama \n", - "1065 Only the Brave Action, Biography, Drama \n", - "1066 Incredibles 2 Animation, Action, Adventure \n", - "1067 A Star Is Born Drama, Music, Romance \n", - "\n", - " Director Cast \\\n", - "0 James Gunn Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... \n", - "1 Ridley Scott Noomi Rapace, Logan Marshall-Green, Michael ... \n", - "2 M. Night Shyamalan James McAvoy, Anya Taylor-Joy, Haley Lu Richar... \n", - "3 Christophe Lourdelet Matthew McConaughey,Reese Witherspoon, Seth Ma... \n", - "4 David Ayer Will Smith, Jared Leto, Margot Robbie, Viola D... \n", - "... ... ... \n", - "1063 James Gunn Chris Pratt, Zoe Saldana, Dave Bautista, Vin D... \n", - "1064 Edgar Wright Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon... \n", - "1065 Joseph Kosinski Josh Brolin, Miles Teller, Jeff Bridges, Jenni... \n", - "1066 Brad Bird Craig T. Nelson, Holly Hunter, Sarah Vowell, H... \n", - "1067 Bradley Cooper Lady Gaga, Bradley Cooper, Sam Elliott, Greg G... \n", - "\n", - " Year Runtime Rating Revenue \n", - "0 2014 121 8.1 333.13 \n", - "1 2012 124 7.0 126.46M \n", - "2 2016 117 7.3 138.12M \n", - "3 2016 108 7.2 270.32 \n", - "4 2016 123 6.2 325.02 \n", - "... ... ... ... ... \n", - "1063 2017 136 7.6 389.81 \n", - "1064 2017 113 7.6 107.83 \n", - "1065 2017 134 7.6 18.34 \n", - "1066 2018 118 7.6 608.58 \n", - "1067 2018 136 7.6 215.29 \n", - "\n", - "[1068 rows x 8 columns]" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Warmup 1: Read the data from \"new_movie_data.csv\" into a pandas DataFrame called \"movies\"\n", - "movies = pd.read_csv(\"new_movie_data.csv\")\n", - "movies" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2006 to 2020\n" - ] - } - ], - "source": [ - "# Warmup 2: What years does this new movie dataset cover?\n", - "print(movies['Year'].min(), 'to', movies['Year'].max())" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "# Warmup 3a: What does this function do?\n", - "def format_revenue(revenue):\n", - " if type(revenue) == float: # need this in here if we run code multiple times\n", - " return revenue\n", - " elif revenue[-1] == 'M': # some have an \"M\" at the end\n", - " return float(revenue[:-1]) * 1e6\n", - " else: # otherwise, assume millions.\n", - " return float(revenue) * 1e6" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>Title</th>\n", - " <th>Genre</th>\n", - " <th>Director</th>\n", - " <th>Cast</th>\n", - " <th>Year</th>\n", - " <th>Runtime</th>\n", - " <th>Rating</th>\n", - " <th>Revenue</th>\n", - " <th>CountableRevenue</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>Guardians of the Galaxy</td>\n", - " <td>Action,Adventure,Sci-Fi</td>\n", - " <td>James Gunn</td>\n", - " <td>Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...</td>\n", - " <td>2014</td>\n", - " <td>121</td>\n", - " <td>8.1</td>\n", - " <td>333.13</td>\n", - " <td>333130000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>Prometheus</td>\n", - " <td>Adventure,Mystery,Sci-Fi</td>\n", - " <td>Ridley Scott</td>\n", - " <td>Noomi Rapace, Logan Marshall-Green, Michael ...</td>\n", - " <td>2012</td>\n", - " <td>124</td>\n", - " <td>7.0</td>\n", - " <td>126.46M</td>\n", - " <td>126460000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>Split</td>\n", - " <td>Horror,Thriller</td>\n", - " <td>M. Night Shyamalan</td>\n", - " <td>James McAvoy, Anya Taylor-Joy, Haley Lu Richar...</td>\n", - " <td>2016</td>\n", - " <td>117</td>\n", - " <td>7.3</td>\n", - " <td>138.12M</td>\n", - " <td>138120000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>Sing</td>\n", - " <td>Animation,Comedy,Family</td>\n", - " <td>Christophe Lourdelet</td>\n", - " <td>Matthew McConaughey,Reese Witherspoon, Seth Ma...</td>\n", - " <td>2016</td>\n", - " <td>108</td>\n", - " <td>7.2</td>\n", - " <td>270.32</td>\n", - " <td>270320000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>Suicide Squad</td>\n", - " <td>Action,Adventure,Fantasy</td>\n", - " <td>David Ayer</td>\n", - " <td>Will Smith, Jared Leto, Margot Robbie, Viola D...</td>\n", - " <td>2016</td>\n", - " <td>123</td>\n", - " <td>6.2</td>\n", - " <td>325.02</td>\n", - " <td>325020000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>...</th>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1063</th>\n", - " <td>Guardians of the Galaxy Vol. 2</td>\n", - " <td>Action, Adventure, Comedy</td>\n", - " <td>James Gunn</td>\n", - " <td>Chris Pratt, Zoe Saldana, Dave Bautista, Vin D...</td>\n", - " <td>2017</td>\n", - " <td>136</td>\n", - " <td>7.6</td>\n", - " <td>389.81</td>\n", - " <td>389810000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1064</th>\n", - " <td>Baby Driver</td>\n", - " <td>Action, Crime, Drama</td>\n", - " <td>Edgar Wright</td>\n", - " <td>Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon...</td>\n", - " <td>2017</td>\n", - " <td>113</td>\n", - " <td>7.6</td>\n", - " <td>107.83</td>\n", - " <td>107830000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1065</th>\n", - " <td>Only the Brave</td>\n", - " <td>Action, Biography, Drama</td>\n", - " <td>Joseph Kosinski</td>\n", - " <td>Josh Brolin, Miles Teller, Jeff Bridges, Jenni...</td>\n", - " <td>2017</td>\n", - " <td>134</td>\n", - " <td>7.6</td>\n", - " <td>18.34</td>\n", - " <td>18340000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1066</th>\n", - " <td>Incredibles 2</td>\n", - " <td>Animation, Action, Adventure</td>\n", - " <td>Brad Bird</td>\n", - " <td>Craig T. Nelson, Holly Hunter, Sarah Vowell, H...</td>\n", - " <td>2018</td>\n", - " <td>118</td>\n", - " <td>7.6</td>\n", - " <td>608.58</td>\n", - " <td>608580000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1067</th>\n", - " <td>A Star Is Born</td>\n", - " <td>Drama, Music, Romance</td>\n", - " <td>Bradley Cooper</td>\n", - " <td>Lady Gaga, Bradley Cooper, Sam Elliott, Greg G...</td>\n", - " <td>2018</td>\n", - " <td>136</td>\n", - " <td>7.6</td>\n", - " <td>215.29</td>\n", - " <td>215290000.0</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "<p>1068 rows × 9 columns</p>\n", - "</div>" - ], - "text/plain": [ - " Title Genre \\\n", - "0 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", - "1 Prometheus Adventure,Mystery,Sci-Fi \n", - "2 Split Horror,Thriller \n", - "3 Sing Animation,Comedy,Family \n", - "4 Suicide Squad Action,Adventure,Fantasy \n", - "... ... ... \n", - "1063 Guardians of the Galaxy Vol. 2 Action, Adventure, Comedy \n", - "1064 Baby Driver Action, Crime, Drama \n", - "1065 Only the Brave Action, Biography, Drama \n", - "1066 Incredibles 2 Animation, Action, Adventure \n", - "1067 A Star Is Born Drama, Music, Romance \n", - "\n", - " Director Cast \\\n", - "0 James Gunn Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... \n", - "1 Ridley Scott Noomi Rapace, Logan Marshall-Green, Michael ... \n", - "2 M. Night Shyamalan James McAvoy, Anya Taylor-Joy, Haley Lu Richar... \n", - "3 Christophe Lourdelet Matthew McConaughey,Reese Witherspoon, Seth Ma... \n", - "4 David Ayer Will Smith, Jared Leto, Margot Robbie, Viola D... \n", - "... ... ... \n", - "1063 James Gunn Chris Pratt, Zoe Saldana, Dave Bautista, Vin D... \n", - "1064 Edgar Wright Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon... \n", - "1065 Joseph Kosinski Josh Brolin, Miles Teller, Jeff Bridges, Jenni... \n", - "1066 Brad Bird Craig T. Nelson, Holly Hunter, Sarah Vowell, H... \n", - "1067 Bradley Cooper Lady Gaga, Bradley Cooper, Sam Elliott, Greg G... \n", - "\n", - " Year Runtime Rating Revenue CountableRevenue \n", - "0 2014 121 8.1 333.13 333130000.0 \n", - "1 2012 124 7.0 126.46M 126460000.0 \n", - "2 2016 117 7.3 138.12M 138120000.0 \n", - "3 2016 108 7.2 270.32 270320000.0 \n", - "4 2016 123 6.2 325.02 325020000.0 \n", - "... ... ... ... ... ... \n", - "1063 2017 136 7.6 389.81 389810000.0 \n", - "1064 2017 113 7.6 107.83 107830000.0 \n", - "1065 2017 134 7.6 18.34 18340000.0 \n", - "1066 2018 118 7.6 608.58 608580000.0 \n", - "1067 2018 136 7.6 215.29 215290000.0 \n", - "\n", - "[1068 rows x 9 columns]" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Warmup 3b: Using the above function, create a new column called\n", - "# \"CountableRevenue\" with the revenue as a float.\n", - "movies[\"CountableRevenue\"] = movies[\"Revenue\"].apply(format_revenue)\n", - "movies" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>Title</th>\n", - " <th>Genre</th>\n", - " <th>Director</th>\n", - " <th>Cast</th>\n", - " <th>Year</th>\n", - " <th>Runtime</th>\n", - " <th>Rating</th>\n", - " <th>Revenue</th>\n", - " <th>CountableRevenue</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>50</th>\n", - " <td>Star Wars: Episode VII - The Force Awakens</td>\n", - " <td>Action,Adventure,Fantasy</td>\n", - " <td>J.J. Abrams</td>\n", - " <td>Daisy Ridley, John Boyega, Oscar Isaac, Domhna...</td>\n", - " <td>2015</td>\n", - " <td>136</td>\n", - " <td>8.1</td>\n", - " <td>936.63</td>\n", - " <td>936630000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1006</th>\n", - " <td>Avengers: Endgame</td>\n", - " <td>Action, Adventure, Drama</td>\n", - " <td>Anthony Russo</td>\n", - " <td>Joe Russo, Robert Downey Jr., Chris Evans, Mar...</td>\n", - " <td>2019</td>\n", - " <td>181</td>\n", - " <td>8.4</td>\n", - " <td>858.37</td>\n", - " <td>858370000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>87</th>\n", - " <td>Avatar</td>\n", - " <td>Action,Adventure,Fantasy</td>\n", - " <td>James Cameron</td>\n", - " <td>Sam Worthington, Zoe Saldana, Sigourney Weaver...</td>\n", - " <td>2009</td>\n", - " <td>162</td>\n", - " <td>7.8</td>\n", - " <td>760.51</td>\n", - " <td>760510000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1007</th>\n", - " <td>Avengers: Infinity War</td>\n", - " <td>Action, Adventure, Sci-Fi</td>\n", - " <td>Anthony Russo</td>\n", - " <td>Joe Russo, Robert Downey Jr., Chris Hemsworth,...</td>\n", - " <td>2018</td>\n", - " <td>149</td>\n", - " <td>8.4</td>\n", - " <td>678.82</td>\n", - " <td>678820000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>85</th>\n", - " <td>Jurassic World</td>\n", - " <td>Action,Adventure,Sci-Fi</td>\n", - " <td>Colin Trevorrow</td>\n", - " <td>Chris Pratt, Bryce Dallas Howard, Ty Simpkins,...</td>\n", - " <td>2015</td>\n", - " <td>124</td>\n", - " <td>7.0</td>\n", - " <td>652.18</td>\n", - " <td>652180000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>76</th>\n", - " <td>The Avengers</td>\n", - " <td>Action,Sci-Fi</td>\n", - " <td>Joss Whedon</td>\n", - " <td>Robert Downey Jr., Chris Evans, Scarlett Johan...</td>\n", - " <td>2012</td>\n", - " <td>143</td>\n", - " <td>8.1</td>\n", - " <td>623.28</td>\n", - " <td>623280000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>998</th>\n", - " <td>Hamilton</td>\n", - " <td>Biography, Drama, History</td>\n", - " <td>Thomas Kail</td>\n", - " <td>Lin-Manuel Miranda, Phillipa Soo, Leslie Odom ...</td>\n", - " <td>2020</td>\n", - " <td>160</td>\n", - " <td>8.6</td>\n", - " <td>612.82</td>\n", - " <td>612820000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1066</th>\n", - " <td>Incredibles 2</td>\n", - " <td>Animation, Action, Adventure</td>\n", - " <td>Brad Bird</td>\n", - " <td>Craig T. Nelson, Holly Hunter, Sarah Vowell, H...</td>\n", - " <td>2018</td>\n", - " <td>118</td>\n", - " <td>7.6</td>\n", - " <td>608.58</td>\n", - " <td>608580000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>54</th>\n", - " <td>The Dark Knight</td>\n", - " <td>Action,Crime,Drama</td>\n", - " <td>Christopher Nolan</td>\n", - " <td>Christian Bale, Heath Ledger, Aaron Eckhart,Mi...</td>\n", - " <td>2008</td>\n", - " <td>152</td>\n", - " <td>9.0</td>\n", - " <td>533.32</td>\n", - " <td>533320000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>12</th>\n", - " <td>Rogue One</td>\n", - " <td>Action,Adventure,Sci-Fi</td>\n", - " <td>Gareth Edwards</td>\n", - " <td>Felicity Jones, Diego Luna, Alan Tudyk, Donnie...</td>\n", - " <td>2016</td>\n", - " <td>133</td>\n", - " <td>7.9</td>\n", - " <td>532.17</td>\n", - " <td>532170000.0</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "</div>" - ], - "text/plain": [ - " Title \\\n", - "50 Star Wars: Episode VII - The Force Awakens \n", - "1006 Avengers: Endgame \n", - "87 Avatar \n", - "1007 Avengers: Infinity War \n", - "85 Jurassic World \n", - "76 The Avengers \n", - "998 Hamilton \n", - "1066 Incredibles 2 \n", - "54 The Dark Knight \n", - "12 Rogue One \n", - "\n", - " Genre Director \\\n", - "50 Action,Adventure,Fantasy J.J. Abrams \n", - "1006 Action, Adventure, Drama Anthony Russo \n", - "87 Action,Adventure,Fantasy James Cameron \n", - "1007 Action, Adventure, Sci-Fi Anthony Russo \n", - "85 Action,Adventure,Sci-Fi Colin Trevorrow \n", - "76 Action,Sci-Fi Joss Whedon \n", - "998 Biography, Drama, History Thomas Kail \n", - "1066 Animation, Action, Adventure Brad Bird \n", - "54 Action,Crime,Drama Christopher Nolan \n", - "12 Action,Adventure,Sci-Fi Gareth Edwards \n", - "\n", - " Cast Year Runtime \\\n", - "50 Daisy Ridley, John Boyega, Oscar Isaac, Domhna... 2015 136 \n", - "1006 Joe Russo, Robert Downey Jr., Chris Evans, Mar... 2019 181 \n", - "87 Sam Worthington, Zoe Saldana, Sigourney Weaver... 2009 162 \n", - "1007 Joe Russo, Robert Downey Jr., Chris Hemsworth,... 2018 149 \n", - "85 Chris Pratt, Bryce Dallas Howard, Ty Simpkins,... 2015 124 \n", - "76 Robert Downey Jr., Chris Evans, Scarlett Johan... 2012 143 \n", - "998 Lin-Manuel Miranda, Phillipa Soo, Leslie Odom ... 2020 160 \n", - "1066 Craig T. Nelson, Holly Hunter, Sarah Vowell, H... 2018 118 \n", - "54 Christian Bale, Heath Ledger, Aaron Eckhart,Mi... 2008 152 \n", - "12 Felicity Jones, Diego Luna, Alan Tudyk, Donnie... 2016 133 \n", - "\n", - " Rating Revenue CountableRevenue \n", - "50 8.1 936.63 936630000.0 \n", - "1006 8.4 858.37 858370000.0 \n", - "87 7.8 760.51 760510000.0 \n", - "1007 8.4 678.82 678820000.0 \n", - "85 7.0 652.18 652180000.0 \n", - "76 8.1 623.28 623280000.0 \n", - "998 8.6 612.82 612820000.0 \n", - "1066 7.6 608.58 608580000.0 \n", - "54 9.0 533.32 533320000.0 \n", - "12 7.9 532.17 532170000.0 " - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Warmup 4: What are the top 10 highest-revenue movies?\n", - "movies.sort_values(by=\"CountableRevenue\", ascending=False).head(10)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Lecture 29: Web 1 - Getting Data\n", - "Learning Objectives\n", - "\n", - "- Make a request for data using `requests.get(URL)`\n", - "- Check the status of a request/response\n", - "- Extract the text of a response\n", - "- Create a json file from a response\n", - "- State and practice good etiquette when getting data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Make a request for data using `requests.get(URL)`\n", - "- URL: https://www.msyamkumar.com/hello.txt" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "200\n", - "Hello CS220 / CS319 students! Welcome to my website. Hope you are staying safe and healthy!\n", - "\n" - ] - } - ], - "source": [ - "url = \"https://www.msyamkumar.com/hello.txt\"\n", - "r = requests.get(url) # r is the response\n", - "print(r.status_code)\n", - "print(r.text)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### HTTP Status Codes you need to know\n", - "\n", - "- 200: success\n", - "- 404: not found\n", - "\n", - "Here is a list of all status codes, you do NOT need to memorize it\n", - "\n", - "https://en.wikipedia.org/wiki/List_of_HTTP_status_codes" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'requests' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m<ipython-input-2-c1918b69a3bc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Q: What if the web site does not exist?\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mtypo_url\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"https://www.msyamkumar.com/hello.txttttt\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtypo_url\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 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatus_code\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'requests' is not defined" - ] - } - ], - "source": [ - "# Q: What if the web site does not exist?\n", - "typo_url = \"https://www.msyamkumar.com/hello.txttttt\"\n", - "r = requests.get(typo_url)\n", - "print(r.status_code)\n", - "print(r.text)\n", - "\n", - "# A: We get a 404 (client error)\n", - "# A: we get text, but the text is not from the client" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Check the status of a request/response\n" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "ename": "AssertionError", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mAssertionError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32mC:\\Users\\COLENE~1\\AppData\\Local\\Temp/ipykernel_5272/4112931377.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mtypo_url\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"https://www.msyamkumar.com/hello.txttttt\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtypo_url\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[1;32massert\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstatus_code\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m200\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstatus_code\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mAssertionError\u001b[0m: " - ] - } - ], - "source": [ - "# We can check for a status_code error by using an assert\n", - "typo_url = \"https://www.msyamkumar.com/hello.txttttt\"\n", - "r = requests.get(typo_url)\n", - "assert r.status_code == 200\n", - "print(r.status_code)\n", - "print(r.text)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "ename": "HTTPError", - "evalue": "404 Client Error: Not Found for url: https://www.msyamkumar.com/hello.txttttt", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mHTTPError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32mC:\\Users\\COLENE~1\\AppData\\Local\\Temp/ipykernel_5272/4051826470.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# Instead of using an assert, we often use raise_for_status()\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtypo_url\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mraise_for_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#similar to asserting r.status_code == 200\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\requests\\models.py\u001b[0m in \u001b[0;36mraise_for_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 951\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 952\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mhttp_error_msg\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 953\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mHTTPError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhttp_error_msg\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 954\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 955\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mclose\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mHTTPError\u001b[0m: 404 Client Error: Not Found for url: https://www.msyamkumar.com/hello.txttttt" - ] - } - ], - "source": [ - "# Instead of using an assert, we often use raise_for_status()\n", - "r = requests.get(typo_url)\n", - "r.raise_for_status() #similar to asserting r.status_code == 200\n", - "r.text\n", - "\n", - "# Note the error you get.... We will use this in the next cell" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'HTTPError' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mHTTPError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32mC:\\Users\\COLENE~1\\AppData\\Local\\Temp/ipykernel_5272/496634748.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtypo_url\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mraise_for_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#similar to asserting r.status_code == 200\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\requests\\models.py\u001b[0m in \u001b[0;36mraise_for_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 952\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mhttp_error_msg\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 953\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mHTTPError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhttp_error_msg\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 954\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mHTTPError\u001b[0m: 404 Client Error: Not Found for url: https://www.msyamkumar.com/hello.txttttt", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32mC:\\Users\\COLENE~1\\AppData\\Local\\Temp/ipykernel_5272/496634748.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mraise_for_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#similar to asserting r.status_code == 200\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;32mexcept\u001b[0m \u001b[0mHTTPError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# What's still wrong here?\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"oops!!\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mNameError\u001b[0m: name 'HTTPError' is not defined" - ] - } - ], - "source": [ - "# Let's try to catch that error\n", - "\n", - "try:\n", - " r = requests.get(typo_url)\n", - " r.raise_for_status() #similar to asserting r.status_code == 200\n", - " r.text\n", - "except HTTPError as e: # What's still wrong here?\n", - " print(\"oops!!\", e)\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "oops!! 404 Client Error: Not Found for url: https://www.msyamkumar.com/hello.txttttt\n" - ] - } - ], - "source": [ - "# we often need to prepend the names of exceptions with the name of the module\n", - "# fix the error from above\n", - "\n", - "try:\n", - " r = requests.get(typo_url)\n", - " r.raise_for_status() #similar to asserting r.status_code == 200\n", - " r.text\n", - "except requests.HTTPError as e: #correct way to catch the error.\n", - " print(\"oops!!\", e)\n", - " \n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create a json file from a response\n", - "\n", - "- URL: https://www.msyamkumar.com/scores.json\n", - "- `json.load` (FILE_OBJECT)\n", - "- `json.loads` (STRING)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\n", - " \"alice\": 100,\n", - " \"bob\": 200,\n", - " \"cindy\": 300\n", - "}\n", - "\n", - "<class 'dict'> {'alice': 100, 'bob': 200, 'cindy': 300}\n" - ] - } - ], - "source": [ - "# GETting a JSON file, the long way\n", - "url = \"https://www.msyamkumar.com/scores.json\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "urltext = r.text\n", - "print(urltext)\n", - "d = json.loads(urltext)\n", - "print(type(d), d)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "<class 'dict'> {'alice': 100, 'bob': 200, 'cindy': 300}\n" - ] - } - ], - "source": [ - "# GETting a JSON file, the shortcut way\n", - "url = \"https://www.msyamkumar.com/scores.json\"\n", - "#Shortcut to bypass using json.loads()\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "d2 = r.json()\n", - "print(type(d2), d2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Good GET Etiquette\n", - "\n", - "Don't make a lot of requests to the same server all at once.\n", - " - Requests use up the server's time\n", - " - Major websites will often ban users who make too many requests\n", - " - You can break a server....similar to DDoS attacks (DON'T DO THIS)\n", - " \n", - "In CS220 we will usually give you a link to a copied file to avoid overloading the site.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## DEMO: Course Enrollment" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Explore the API!\n", - "\n", - "https://coletnelson.us/cs220-api/classes\n", - "\n", - "https://coletnelson.us/cs220-api/classes_as_txt\n", - "\n", - "https://coletnelson.us/cs220-api/classes/MATH_221\n", - "\n", - "https://coletnelson.us/cs220-api/classes/COMPSCI_200\n", - "\n", - "... etc\n", - "\n", - "https://coletnelson.us/cs220-api/all_data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Get the list of classes." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### When the data is `json`" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "<class 'list'>\n", - "['PSYCH_202', 'COMPSCI_537', 'COMPSCI_300', 'CHEM_104', 'COMPSCI_200', 'MATH_114', 'PSYCH_456', 'COMPSCI_252', 'COMPSCI_400', 'MATH_221', 'BIOLOGY_101', 'COMPSCI_354', 'CHEM_103', 'COMPSCI_639', 'PSYCH_401', 'COMPSCI_240', 'STATS_302']\n" - ] - } - ], - "source": [ - "url = \"https://coletnelson.us/cs220-api/classes\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "classes_list = r.json()\n", - "print(type(classes_list))\n", - "print(classes_list)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### When the data is `text`" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "<class 'str'>\n", - "PSYCH_202\n", - "COMPSCI_537\n", - "COMPSCI_300\n", - "CHEM_104\n", - "COMPSCI_200\n", - "MATH_114\n", - "PSYCH_456\n", - "COMPSCI_252\n", - "COMPSCI_400\n", - "MATH_221\n", - "BIOLOGY_101\n", - "COMPSCI_354\n", - "CHEM_103\n", - "COMPSCI_639\n", - "PSYCH_401\n", - "COMPSCI_240\n", - "STATS_302\n" - ] - } - ], - "source": [ - "url = \"https://coletnelson.us/cs220-api/classes_as_txt\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "classes_txt = r.text\n", - "print(type(classes_txt))\n", - "print(classes_txt)" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['PSYCH_202',\n", - " 'COMPSCI_537',\n", - " 'COMPSCI_300',\n", - " 'CHEM_104',\n", - " 'COMPSCI_200',\n", - " 'MATH_114',\n", - " 'PSYCH_456',\n", - " 'COMPSCI_252',\n", - " 'COMPSCI_400',\n", - " 'MATH_221',\n", - " 'BIOLOGY_101',\n", - " 'COMPSCI_354',\n", - " 'CHEM_103',\n", - " 'COMPSCI_639',\n", - " 'PSYCH_401',\n", - " 'COMPSCI_240',\n", - " 'STATS_302']" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "classes_txt_as_list = classes_txt.split('\\n')\n", - "classes_txt_as_list" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Get data for a specific class" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "<class 'dict'>\n", - "{'credits': 3, 'description': 'Learn the process of incrementally developing small (200-500 lines) programs along with the fundamental Computer Science topics. These topics include: problem abstraction and decomposition, the edit-compile-run cycle, using variables of primitive and more complex data types, conditional and loop-based flow control, basic testing and debugging techniques, how to define and call functions (methods), and IO processing techniques. Also teaches and reinforces good programming practices including the use of a consistent style, and meaningful documentation. Intended for students who have no prior programming experience.', 'keywords': ['computer', 'science', 'programming', 'java'], 'name': 'Programming 1', 'number': 'COMPSCI_200', 'requisites': [], 'sections': [{'instructor': 'Jim Williams', 'location': '132 Noland Hall', 'subsections': [{'location': '1350 Computer Sciences and Statistics', 'time': {'wednesday': '9:30am - 10:45am'}, 'number': 'LAB_311'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'wednesday': '11:00am - 12:15pm'}, 'number': 'LAB_312'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'wednesday': '2:30pm - 3:45pm'}, 'number': 'LAB_314'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'wednesday': '4:00pm - 5:15pm'}, 'number': 'LAB_315'}], 'time': {'thursday': '8:00am - 9:15am', 'tuesday': '8:00am - 9:15am'}, 'number': 'LEC_001'}, {'instructor': 'Jim Williams', 'location': '132 Noland Hall', 'subsections': [{'location': '1370 Computer Sciences and Statistics', 'time': {'wednesday': '9:30am - 10:45am'}, 'number': 'LAB_321'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'wednesday': '1:00pm - 2:15pm'}, 'number': 'LAB_323'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'wednesday': '2:30pm - 3:45pm'}, 'number': 'LAB_324'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'wednesday': '4:00pm - 5:15pm'}, 'number': 'LAB_325'}], 'time': {'thursday': '11:00am - 12:15pm', 'tuesday': '11:00am - 12:15pm'}, 'number': 'LEC_002'}, {'instructor': 'Marc Renault', 'location': '113 Brogden Psychology Building', 'subsections': [{'location': '1350 Computer Sciences and Statistics', 'time': {'tuesday': '9:30am - 10:45am'}, 'number': 'LAB_331'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'tuesday': '11:00am - 12:15pm'}, 'number': 'LAB_332'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'tuesday': '1:00pm - 2:15pm'}, 'number': 'LAB_333'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'tuesday': '2:30pm - 3:45pm'}, 'number': 'LAB_334'}], 'time': {'friday': '1:20pm - 2:10pm', 'monday': '1:20pm - 2:10pm', 'wednesday': '1:20pm - 2:10pm'}, 'number': 'LEC_003'}, {'instructor': 'Marc Renault', 'location': '113 Brogden Psychology Building', 'subsections': [{'location': '1370 Computer Sciences and Statistics', 'time': {'tuesday': '9:30am - 10:45am'}, 'number': 'LAB_341'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'tuesday': '11:00am - 12:15pm'}, 'number': 'LAB_342'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'tuesday': '1:00pm - 2:15pm'}, 'number': 'LAB_343'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'tuesday': '2:30pm - 3:45pm'}, 'number': 'LAB_344'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'tuesday': '4:00pm - 5:15pm'}, 'number': 'LAB_345'}], 'time': {'friday': '3:30pm - 4:20pm', 'monday': '3:30pm - 4:20pm', 'wednesday': '3:30pm - 4:20pm'}, 'number': 'LEC_004'}], 'subject': 'Computer Science'}\n" - ] - } - ], - "source": [ - "url = \"https://coletnelson.us/cs220-api/classes/COMPSCI_200\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "cs200_data = r.json()\n", - "print(type(cs200_data))\n", - "print(cs200_data) # Too much data? Try print(cs220_data.keys())" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "dict_keys(['credits', 'description', 'keywords', 'name', 'number', 'requisites', 'sections', 'subject'])" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "cs200_data.keys()" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Get the number of credits the course is worth\n", - "cs200_data['credits']" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['computer', 'science', 'programming', 'java']" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Get the list of keywords for the course\n", - "cs200_data['keywords']" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Programming 1'" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Get the official course name\n", - "cs200_data['name']" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "4" - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Get the number of sections offered.\n", - "len(cs200_data['sections'])" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'credits': 3, 'description': 'Behavior, including its development, motivation, frustrations, emotion, intelligence, learning, forgetting, personality, language, thinking, and social behavior.', 'keywords': ['psychology', 'behavior', 'emotion', 'intelligence', 'brain'], 'name': 'Introduction to Psychology', 'number': 'PSYCH_202', 'requisites': [], 'sections': [{'instructor': 'Jeff Henriques', 'location': '105 Brogden Psychology Building', 'subsections': [], 'time': {'thursday': '9:30am - 10:45am', 'tuesday': '9:30am - 10:45am'}, 'number': 'LEC_001'}, {'instructor': 'Jeff Henriques', 'location': '105 Brogden Psychology Building', 'subsections': [], 'time': {'thursday': '11:00am - 12:15pm', 'tuesday': '11:00am - 12:15pm'}, 'number': 'LEC_002'}, {'instructor': 'C. Shawn Green', 'location': '105 Brogden Psychology Building', 'subsections': [], 'time': {'monday': '8:00am - 9:15am', 'wednesday': '8:00am - 9:15am'}, 'number': 'LEC_003'}, {'instructor': 'Patti Coffey', 'location': '105 Brogden Psychology Building', 'subsections': [], 'time': {'thursday': '1:00pm - 2:15pm', 'tuesday': '1:00pm - 2:15pm'}, 'number': 'LEC_004'}, {'instructor': 'Sarah Gavac', 'location': '105 Brogden Psychology Building', 'subsections': [], 'time': {'thursday': '2:30pm - 3:45pm', 'tuesday': '2:30pm - 3:45pm'}, 'number': 'LEC_005'}, {'instructor': 'Patti Coffey', 'location': '101 Brogden Psychology Building', 'subsections': [], 'time': {'thursday': '2:30pm - 3:45pm', 'tuesday': '2:30pm - 3:45pm'}, 'number': 'LEC_006'}, {'instructor': 'Baoyu Wang', 'location': '105 Brogden Psychology Building', 'subsections': [], 'time': {'monday': '4:30pm - 5:15pm', 'wednesday': '4:30pm - 5:15pm'}, 'number': 'LEC_009'}], 'subject': 'Psychology'}, {'credits': 4, 'description': 'Input-output hardware, interrupt handling, properties of magnetic tapes, discs and drums, associative memories and virtual address translation techniques. Batch processing, time sharing and real-time systems, scheduling resource allocation, modular software systems, performance measurement and system evaluation.', 'keywords': ['computer', 'science', 'operating', 'system', 'systems'], 'name': 'Introduction to Operating Systems', 'number': 'COMPSCI_537', 'requisites': [['COMPSCI_354', 'COMPSCI_400']], 'sections': [{'instructor': 'Andrea Arpaci-Dusseau', 'location': '1125 DeLuca Biochemistry Building', 'subsections': [{'location': '2317 Engineering Hall', 'time': {'wednesday': '11:00am - 11:50am'}, 'number': 'DIS_301'}, {'location': '1325 Computer Sciences and Statistics', 'time': {'wednesday': '12:05pm - 12:55pm'}, 'number': 'DIS_302'}, {'location': '1325 Computer Sciences and Statistics', 'time': {'wednesday': '1:20pm - 2:10pm'}, 'number': 'DIS_303'}, {'location': '2255 Engineering Hall', 'time': {'wednesday': '3:30pm - 4:20pm'}, 'number': 'DIS_304'}, {'location': '1325 Computer Sciences and Statistics', 'time': {'wednesday': '4:15pm - 5:25pm'}, 'number': 'DIS_305'}], 'time': {'thursday': '11:00am - 12:15pm', 'tuesday': '11:00am - 12:15pm'}, 'number': 'LEC_001'}], 'subject': 'Computer Science'}, {'credits': 3, 'description': 'Introduces students to Object-Oriented Programming using classes and objects to solve more complex problems. Introduces array-based and linked data structures: including lists, stacks, and queues. Programming assignments require writing and developing multi-class (file) programs using interfaces, generics, and exception handling to solve challenging real world problems. Topics reviewed include reading/writing data and objects from/to files and exception handling, and command line arguments. Topics introduced: object-oriented design; class vs. object; create and define interfaces and iterators; searching and sorting; abstract data types (List,Stack,Queue,PriorityQueue(Heap),Binary Search Tree); generic interfaces (parametric polymorphism); how to design and write test methods and classes; array based vs. linked node implementations; introduction to complexity analysis; recursion.', 'keywords': ['computer', 'science', 'programming', 'java'], 'name': 'Programming 2', 'number': 'COMPSCI_300', 'requisites': [['COMPSCI_200']], 'sections': [{'instructor': 'Gary Dahl', 'location': 'AB20 Weeks Hall for Geological Sciences', 'subsections': [], 'time': {'thursday': '2:30pm - 3:45pm', 'tuesday': '2:30pm - 3:45pm'}, 'number': 'LEC_001'}, {'instructor': 'Gary Dahl', 'location': '132 Noland Hall', 'subsections': [], 'time': {'thursday': '1:00pm - 2:15pm', 'tuesday': '1:00pm - 2:15pm'}, 'number': 'LEC_002'}, {'instructor': 'Mouna Ayari Ben Hadj Kacem', 'location': 'AB20 Weeks Hall for Geological Sciences', 'subsections': [], 'time': {'friday': '11:00am - 11:50pm', 'monday': '11:00am - 11:50pm', 'wednesday': '11:00am - 11:50pm'}, 'number': 'LEC_003'}, {'instructor': 'Mouna Ayari Ben Hadj Kacem', 'location': '1310 Sterling Hall', 'subsections': [], 'time': {'friday': '2:25pm - 3:15pm', 'monday': '2:25pm - 3:15pm', 'wednesday': '2:25pm - 3:15pm'}, 'number': 'LEC_004'}], 'subject': 'Computer Science'}, {'credits': 5, 'description': 'Principles and application of chemical equilibrium, coordination chemistry, oxidation-reduction and electrochemistry, kinetics, nuclear chemistry, introduction to organic chemistry. Lecture, lab, and discussion.', 'keywords': ['chemistry'], 'name': 'General Chemistry II', 'number': 'CHEM_104', 'requisites': [['MATH_114'], ['CHEM_103']], 'sections': [{'instructor': 'Linda Zelewski', 'location': 'B10 Ingraham Hall', 'subsections': [{'location': '123 Van Hise Hall', 'time': {'monday': '2:25pm - 5:25pm', 'thursday': '11:00am - 11:50am', 'tuesday': '11:00am - 11:50am'}, 'number': 'DIS_401'}, {'location': '123 Van Hise Hall', 'time': {'monday': '2:25pm - 5:25pm', 'thursday': '12:05pm - 12:55pm', 'tuesday': '12:05pm - 12:55pm'}, 'number': 'DIS_402'}, {'location': 'B387 Chemistry Building', 'time': {'monday': '2:25pm - 5:25pm', 'thursday': '11:00am - 11:50am', 'tuesday': '11:00am - 11:50am'}, 'number': 'DIS_403'}, {'location': 'B387 Chemistry Building', 'time': {'monday': '2:25pm - 5:25pm', 'thursday': '12:05pm - 12:55pm', 'tuesday': '12:05pm - 12:55pm'}, 'number': 'DIS_404'}], 'time': {'thursday': '9:30am - 10:45am', 'tuesday': '9:30am - 10:45am'}, 'number': 'LEC_001'}, {'instructor': 'Lea Gustin', 'location': '204 Educational Sciences', 'subsections': [{'location': '2377 Chemistry Building', 'time': {'monday': '9:55am - 10:45am', 'tuesday': '5:40pm - 8:40pm', 'wednesday': '9:55am - 10:45am'}, 'number': 'DIS_421'}, {'location': '2377 Chemistry Building', 'time': {'monday': '11:00am - 11:50am', 'tuesday': '5:40pm - 8:40pm', 'wednesday': '11:00am - 11:50am'}, 'number': 'DIS_422'}, {'location': '2381 Chemistry Building', 'time': {'monday': '11:00am - 11:50am', 'tuesday': '5:40pm - 8:40pm', 'wednesday': '11:00am - 11:50am'}, 'number': 'DIS_423'}, {'location': '2377 Chemistry Building', 'time': {'monday': '12:05pm - 12:55pm', 'tuesday': '5:40pm - 8:40pm', 'wednesday': '12:05pm - 12:55pm'}, 'number': 'DIS_424'}], 'time': {'thursday': '1:00pm - 2:15pm', 'tuesday': '1:00pm - 2:15pm'}, 'number': 'LEC_002'}], 'subject': 'Chemistry'}, {'credits': 3, 'description': 'Learn the process of incrementally developing small (200-500 lines) programs along with the fundamental Computer Science topics. These topics include: problem abstraction and decomposition, the edit-compile-run cycle, using variables of primitive and more complex data types, conditional and loop-based flow control, basic testing and debugging techniques, how to define and call functions (methods), and IO processing techniques. Also teaches and reinforces good programming practices including the use of a consistent style, and meaningful documentation. Intended for students who have no prior programming experience.', 'keywords': ['computer', 'science', 'programming', 'java'], 'name': 'Programming 1', 'number': 'COMPSCI_200', 'requisites': [], 'sections': [{'instructor': 'Jim Williams', 'location': '132 Noland Hall', 'subsections': [{'location': '1350 Computer Sciences and Statistics', 'time': {'wednesday': '9:30am - 10:45am'}, 'number': 'LAB_311'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'wednesday': '11:00am - 12:15pm'}, 'number': 'LAB_312'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'wednesday': '2:30pm - 3:45pm'}, 'number': 'LAB_314'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'wednesday': '4:00pm - 5:15pm'}, 'number': 'LAB_315'}], 'time': {'thursday': '8:00am - 9:15am', 'tuesday': '8:00am - 9:15am'}, 'number': 'LEC_001'}, {'instructor': 'Jim Williams', 'location': '132 Noland Hall', 'subsections': [{'location': '1370 Computer Sciences and Statistics', 'time': {'wednesday': '9:30am - 10:45am'}, 'number': 'LAB_321'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'wednesday': '1:00pm - 2:15pm'}, 'number': 'LAB_323'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'wednesday': '2:30pm - 3:45pm'}, 'number': 'LAB_324'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'wednesday': '4:00pm - 5:15pm'}, 'number': 'LAB_325'}], 'time': {'thursday': '11:00am - 12:15pm', 'tuesday': '11:00am - 12:15pm'}, 'number': 'LEC_002'}, {'instructor': 'Marc Renault', 'location': '113 Brogden Psychology Building', 'subsections': [{'location': '1350 Computer Sciences and Statistics', 'time': {'tuesday': '9:30am - 10:45am'}, 'number': 'LAB_331'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'tuesday': '11:00am - 12:15pm'}, 'number': 'LAB_332'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'tuesday': '1:00pm - 2:15pm'}, 'number': 'LAB_333'}, {'location': '1350 Computer Sciences and Statistics', 'time': {'tuesday': '2:30pm - 3:45pm'}, 'number': 'LAB_334'}], 'time': {'friday': '1:20pm - 2:10pm', 'monday': '1:20pm - 2:10pm', 'wednesday': '1:20pm - 2:10pm'}, 'number': 'LEC_003'}, {'instructor': 'Marc Renault', 'location': '113 Brogden Psychology Building', 'subsections': [{'location': '1370 Computer Sciences and Statistics', 'time': {'tuesday': '9:30am - 10:45am'}, 'number': 'LAB_341'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'tuesday': '11:00am - 12:15pm'}, 'number': 'LAB_342'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'tuesday': '1:00pm - 2:15pm'}, 'number': 'LAB_343'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'tuesday': '2:30pm - 3:45pm'}, 'number': 'LAB_344'}, {'location': '1370 Computer Sciences and Statistics', 'time': {'tuesday': '4:00pm - 5:15pm'}, 'number': 'LAB_345'}], 'time': {'friday': '3:30pm - 4:20pm', 'monday': '3:30pm - 4:20pm', 'wednesday': '3:30pm - 4:20pm'}, 'number': 'LEC_004'}], 'subject': 'Computer Science'}, {'credits': 5, 'description': 'The two semester sequence MATH_112-MATH_113 covers similar material as MATH_114, but in a slower pace.', 'keywords': ['math', 'mathematics', 'algebra', 'trigonometry'], 'name': 'Algebra and Trigonometry', 'number': 'MATH_114', 'requisites': [], 'sections': [{'instructor': 'Sharad Chandarana', 'location': 'B130 Van Vleck Hall', 'subsections': [{'location': 'B113 Van Vleck Hall', 'time': {'monday': '7:45am - 8:35am', 'wednesday': '7:45am - 8:35am'}, 'number': 'DIS_301'}, {'location': 'B113 Van Vleck Hall', 'time': {'monday': '8:50am - 9:40am', 'wednesday': '8:50am - 9:40am'}, 'number': 'DIS_303'}, {'location': 'B219 Van Vleck Hall', 'time': {'monday': '8:50am - 9:40am', 'wednesday': '8:50am - 9:40am'}, 'number': 'DIS_304'}, {'location': 'B113 Van Vleck Hall', 'time': {'monday': '9:55am - 10:45am', 'wednesday': '9:55am - 10:45am'}, 'number': 'DIS_305'}, {'location': 'B219 Van Vleck Hall', 'time': {'monday': '9:55am - 10:45am', 'wednesday': '9:55am - 10:45am'}, 'number': 'DIS_306'}, {'location': 'B341 Van Vleck Hall', 'time': {'monday': '1:20pm - 2:10pm', 'wednesday': '1:20pm - 2:10pm'}, 'number': 'DIS_307'}, {'location': 'B317 Van Vleck Hall', 'time': {'monday': '1:20pm - 2:10pm', 'wednesday': '1:20pm - 2:10pm'}, 'number': 'DIS_308'}, {'location': 'B341 Van Vleck Hall', 'time': {'monday': '2:25pm - 3:15pm', 'wednesday': '2:25pm - 3:15pm'}, 'number': 'DIS_309'}, {'location': 'B329 Van Vleck Hall', 'time': {'monday': '2:25pm - 3:15pm', 'wednesday': '2:25pm - 3:15pm'}, 'number': 'DIS_310'}, {'location': 'B317 Van Vleck Hall', 'time': {'monday': '7:45am - 8:35am', 'wednesday': '7:45am - 8:35am'}, 'number': 'DIS_311'}], 'time': {'thursday': '2:30pm - 3:45pm', 'tuesday': '2:30pm - 3:45pm'}, 'number': 'LEC_001'}, {'instructor': 'Sharad Chandarana', 'location': '19 Ingraham Hall', 'subsections': [{'location': '591 Van Hise Hall', 'time': {'thursday': '8:50am - 9:40am', 'tuesday': '8:50am - 9:40am'}, 'number': 'DIS_321'}, {'location': 'B219 Van Vleck Hall', 'time': {'thursday': '9:55am - 10:45am', 'tuesday': '9:55am - 10:45am'}, 'number': 'DIS_322'}, {'location': '4020 Vilas Hall', 'time': {'thursday': '11:00am - 11:50am', 'tuesday': '11:00am - 11:50am'}, 'number': 'DIS_323'}, {'location': '599 Van Hise Hall', 'time': {'thursday': '11:00am - 11:50am', 'tuesday': '11:00am - 11:50am'}, 'number': 'DIS_324'}, {'location': 'B341 Van Vleck Hall', 'time': {'thursday': '1:20pm - 2:10pm', 'tuesday': '1:20pm - 2:10pm'}, 'number': 'DIS_325'}, {'location': '223 Van Hise Hall', 'time': {'thursday': '1:20pm - 2:10pm', 'tuesday': '1:20pm - 2:10pm'}, 'number': 'DIS_326'}, {'location': '223 Van Hise Hall', 'time': {'thursday': '2:25pm - 3:15pm', 'tuesday': '2:25pm - 3:15pm'}, 'number': 'DIS_328'}, {'location': 'B219 Van Vleck Hall', 'time': {'thursday': '3:30pm - 4:20pm', 'tuesday': '3:30pm - 4:20pm'}, 'number': 'DIS_329'}, {'location': 'B341 Van Vleck Hall', 'time': {'thursday': '3:30pm - 4:20pm', 'tuesday': '3:30pm - 4:20pm'}, 'number': 'DIS_330'}], 'time': {'friday': '8:50am - 9:40am', 'monday': '8:50am - 9:40am', 'wednesday': '8:50am - 9:40am'}, 'number': 'LEC_002'}], 'subject': 'Mathematics'}, {'credits': 4, 'description': 'The systematic study of the individual in a social context, including social interaction, motivation, attitudes, conformity, communication, leadership, personal relationships, and behavior in small groups.', 'keywords': ['psychology', 'science', 'social', 'interaction', 'behavior'], 'name': 'Introductory Social Psychology', 'number': 'PSYCH_456', 'requisites': [['PSYCH_202']], 'sections': [{'instructor': 'Abigail Letak', 'location': '6104 Sewell Social Sciences', 'subsections': [{'location': '6121 Sewell Social Sciences', 'time': {'tuesday': '8:50am - 9:40am'}, 'number': 'DIS_301'}, {'location': '6121 Sewell Social Sciences', 'time': {'tuesday': '9:55am - 10:45am'}, 'number': 'DIS_302'}, {'location': '6121 Sewell Social Sciences', 'time': {'tuesday': '11:00am - 11:50am'}, 'number': 'DIS_303'}, {'location': '6121 Sewell Social Sciences', 'time': {'tuesday': '1:20pm - 2:10pm'}, 'number': 'DIS_304'}, {'location': '6121 Sewell Social Sciences', 'time': {'tuesday': '2:25pm - 3:15pm'}, 'number': 'DIS_305'}], 'time': {'friday': '11:00am - 11:50am', 'monday': '11:00am - 11:50am', 'wednesday': '11:00am - 11:50am'}, 'number': 'LEC_001'}], 'subject': 'Psychology'}, {'credits': 2, 'description': 'Logic components built with transistors, rudimentary Boolean algebra, basic combinational logic design, basic synchronous sequential logic design, basic computer organization and design, introductory machine- and assembly-language programming.', 'keywords': ['computer', 'science', 'engineering', 'programming'], 'name': 'Introduction to Computer Engineering', 'number': 'COMPSCI_252', 'requisites': [], 'sections': [{'instructor': 'Joseph Krachey', 'location': '1610 Engineering Hall', 'subsections': [], 'time': {'friday': '2:25pm - 3:15pm', 'monday': '2:25pm - 3:15pm', 'wednesday': '2:25pm - 3:15pm'}, 'number': 'LEC_001'}, {'instructor': 'Adil Ibrahim', 'location': '113 Brogden Psychology Building', 'subsections': [], 'time': {'friday': '8:50am - 9:40am', 'monday': '8:50am - 9:40am', 'wednesday': '8:50am - 9:40am'}, 'number': 'LEC_002'}, {'instructor': 'Adil Ibrahim', 'location': '113 Brogden Psychology Building', 'subsections': [], 'time': {'friday': '12:05pm - 12:55pm', 'monday': '12:05pm - 12:55pm', 'wednesday': '12:05pm - 12:55pm'}, 'number': 'LEC_005'}], 'subject': 'Computer Science'}, {'credits': 3, 'description': 'The third course in our programming fundamentals sequence. It presumes that students understand and use functional and object-oriented design and abstract data types as needed. This course introduces balanced search trees, graphs, graph traversal algorithms, hash tables and sets, and complexity analysis and about classes of problems that require each data type. Students are required to design and implement using high quality professional code, a medium sized program, that demonstrates knowledge and use of latest language features, tools, and conventions. Additional topics introduced will include as needed for projects: inheritance and polymorphism; anonymous inner classes, lambda functions, performance analysis to discover and optimize critical code blocks. Students learn about industry standards for code development. Students will design and implement a medium size project with a more advanced user-interface design, such as a web or mobile application with a GUI and event- driven implementation; use of version-control software.', 'keywords': ['computer', 'science', 'programming', 'java'], 'name': 'Programming 3', 'number': 'COMPSCI_400', 'requisites': [['COMPSCI_300']], 'sections': [{'instructor': 'Gary Dahl', 'location': 'AB20 Weeks Hall for Geological Sciences', 'subsections': [], 'time': {'thursday': '2:30pm - 3:45pm', 'tuesday': '2:30pm - 3:45pm'}, 'number': 'LEC_001'}, {'instructor': 'Gary Dahl', 'location': '132 Noland Hall', 'subsections': [], 'time': {'thursday': '1:00pm - 2:15pm', 'tuesday': '1:00pm - 2:15pm'}, 'number': 'LEC_002'}, {'instructor': 'Mouna Ayari Ben Hadj Kacem', 'location': 'AB20 Weeks Hall for Geological Sciences', 'subsections': [], 'time': {'friday': '11:00am - 11:50pm', 'monday': '11:00am - 11:50pm', 'wednesday': '11:00am - 11:50pm'}, 'number': 'LEC_003'}, {'instructor': 'Mouna Ayari Ben Hadj Kacem', 'location': '1310 Sterling Hall', 'subsections': [], 'time': {'friday': '2:25pm - 3:15pm', 'monday': '2:25pm - 3:15pm', 'wednesday': '2:25pm - 3:15pm'}, 'number': 'LEC_004'}], 'subject': 'Computer Science'}, {'credits': 5, 'description': 'Introduction to differential and integral calculus and plane analytic geometry; applications; transcendental functions.', 'keywords': ['math', 'mathematics', 'calculus', 'analytical', 'geometry', 'differential', 'integral'], 'name': 'Calculus and Analytical Geometry 1', 'number': 'MATH_221', 'requisites': [['MATH_114']], 'sections': [{'instructor': 'Laurentiu Maxim', 'location': '6210 Sewell Social Sciences', 'subsections': [{'location': 'B231 Van Vleck Hall', 'time': {'monday': '7:45am - 8:35am', 'wednesday': '7:45am - 8:35am'}, 'number': 'DIS_301'}, {'location': 'B215 Van Vleck Hall', 'time': {'monday': '7:45am - 8:35am', 'wednesday': '7:45am - 8:35am'}, 'number': 'DIS_302'}, {'location': 'B309 Van Vleck Hall', 'time': {'monday': '3:30pm - 4:20pm', 'wednesday': '3:30pm - 4:20pm'}, 'number': 'DIS_303'}, {'location': 'B211 Van Vleck Hall', 'time': {'monday': '3:30pm - 4:20pm', 'wednesday': '3:30pm - 4:20pm'}, 'number': 'DIS_304'}, {'location': 'B129 Van Vleck Hall', 'time': {'monday': '11:00am - 11:50am', 'wednesday': '11:00am - 11:50am'}, 'number': 'DIS_305'}, {'location': 'B131 Van Vleck Hall', 'time': {'monday': '11:00am - 11:50am', 'wednesday': '11:00am - 11:50am'}, 'number': 'DIS_306'}, {'location': 'B231 Van Vleck Hall', 'time': {'monday': '12:05pm - 12:55pm', 'wednesday': '12:05pm - 12:55pm'}, 'number': 'DIS_307'}, {'location': 'B215 Van Vleck Hall', 'time': {'monday': '12:05pm - 12:55pm', 'wednesday': '12:05pm - 12:55pm'}, 'number': 'DIS_308'}, {'location': 'B313 Van Vleck Hall', 'time': {'monday': '1:20pm - 2:10pm', 'wednesday': '1:20pm - 2:10pm'}, 'number': 'DIS_309'}, {'location': 'B309 Van Vleck Hall', 'time': {'monday': '1:20pm - 2:10pm', 'wednesday': '1:20pm - 2:10pm'}, 'number': 'DIS_310'}, {'location': 'B305 Van Vleck Hall', 'time': {'monday': '2:25pm - 3:15pm', 'wednesday': '2:25pm - 3:15pm'}, 'number': 'DIS_311'}, {'location': 'B105 Van Vleck Hall', 'time': {'monday': '2:25pm - 3:15pm', 'wednesday': '2:25pm - 3:15pm'}, 'number': 'DIS_312'}, {'location': 'B321 Van Vleck Hall', 'time': {'friday': '9:55am - 10:45am', 'monday': '9:55am - 10:45am', 'wednesday': '9:55am - 10:45am'}, 'number': 'DIS_313'}], 'time': {'thursday': '1:00pm - 2:15pm', 'tuesday': '1:00pm - 2:15pm'}, 'number': 'LEC_001'}], 'subject': 'Mathematics'}, {'credits': 3, 'description': 'General biological principles. Topics include: evolution, ecology, animal behavior, cell structure and function, genetics and molecular genetics and the physiology of a variety of organ systems emphasizing function in humans.', 'keywords': ['biology', 'science', 'animal', 'evolution', 'genetics', 'ecology'], 'name': 'Animal Biology', 'number': 'BIOLOGY_101', 'requisites': [], 'sections': [{'instructor': 'Sharon Thoma', 'location': '272 Bascom Hall', 'subsections': [], 'time': {'friday': '11:00am - 11:50am', 'monday': '11:00am - 11:50am', 'wednesday': '11:00am - 11:50am'}, 'number': 'LEC_001'}, {'instructor': 'Sharon Thoma', 'location': '272 Bascom Hall', 'subsections': [], 'time': {'friday': '12:05pm - 12:55pm', 'monday': '12:05pm - 12:55pm', 'wednesday': '12:05pm - 12:55pm'}, 'number': 'LEC_002'}], 'subject': 'Biology'}, {'credits': 3, 'description': 'An introduction to fundamental structures of computer systems and the C programming language with a focus on the low-level interrelationships and impacts on performance. Topics include the virtual address space and virtual memory, the heap and dynamic memory management, the memory hierarchy and caching, assembly language and the stack, communication and interrupts/signals, compiling and assemblers/linkers.', 'keywords': ['computer', 'science', 'engineering', 'electrical', 'machine', 'programming'], 'name': 'Machine Organization and Programming', 'number': 'COMPSCI_354', 'requisites': [['COMPSCI_252'], ['COMPSCI_300']], 'sections': [{'instructor': 'James Skrentny', 'location': '132 Noland Hall', 'subsections': [], 'time': {'thursday': '2:30pm - 3:45pm', 'tuesday': '2:30pm - 3:45pm'}, 'number': 'LEC_001'}, {'instructor': 'James Skrentny', 'location': '132 Noland Hall', 'subsections': [], 'time': {'thursday': '4:00pm - 5:15pm', 'tuesday': '4:00pm - 5:15pm'}, 'number': 'LEC_002'}], 'subject': 'Computer Science'}, {'credits': 4, 'description': 'Introduction. Stoichiometry and the mole concept, the behavior of gases, liquids and solids, thermochemistry, electronic structure of atoms and chemical bonding, descriptive chemistry of selected elements and compounds, intermolecular forces. For students taking one year or more of college chemistry; serves as a prereq for CHEM_104; lecture, lab and discussion.', 'keywords': ['chemistry'], 'name': 'General Chemistry I', 'number': 'CHEM_103', 'requisites': [], 'sections': [{'instructor': 'Unknown', 'location': 'B10 Ingraham Hall', 'subsections': [{'location': '49 Sellery Residence Hall', 'time': {'monday': '3:30pm - 4:20pm', 'wednesday': '3:30pm - 4:20pm'}, 'number': 'DIS_301'}, {'location': '2307 Chemistry Building', 'time': {'monday': '4:35pm - 5:25pm', 'wednesday': '4:35pm - 5:25pm'}, 'number': 'DIS_302'}, {'location': '123 Van Hise Hall', 'time': {'monday': '1:20pm - 2:10pm', 'wednesday': '1:20pm - 2:10pm'}, 'number': 'DIS_303'}, {'location': '123 Van Hise Hall', 'time': {'monday': '2:25pm - 3:15pm', 'wednesday': '2:25pm - 3:15pm'}, 'number': 'DIS_304'}], 'time': {'friday': '11:00am - 11:50am', 'monday': '11:00am - 11:50am', 'wednesday': '11:00am - 11:50am'}, 'number': 'LEC_001'}], 'subject': 'Chemistry'}, {'credits': 3, 'description': 'This course introduces students to the software development of user interfaces (UIs). Topics covered include state-of-the-art (1) UI paradigms, such as event-driven interfaces, direct-manipulation interfaces, and dialogue-based interaction; (2) methods for capturing, interpreting, and responding to different forms of user input and states, including pointing, text entry, speech, touch, gestures, user activity, context, and physiological states; and (3) platform-specific UI development APIs, frameworks, and toolkits for platforms including web/mobile/desktop interfaces, natural user interfaces, and voice user interfaces. Through readings, lectures, and hands-on-activities, students will learn about the fundamental concepts, technologies, and methods in building user interfaces. Assignments will provide an opportunity to gain hands-on experience in the use of state-of-the-art UI development tools and build a UI development portfolio.', 'keywords': ['computer', 'science', 'building', 'user', 'interface', 'interfaces', 'design', 'ui'], 'name': 'Building User Interfaces', 'number': 'COMPSCI_639', 'requisites': [['COMPSCI_300']], 'sections': [{'instructor': 'Bilge Mutlu', 'location': '1221 Computer Sciences and Statistics', 'subsections': [], 'time': {'thursday': '1:00pm - 2:15pm', 'tuesday': '1:00pm - 2:15pm'}, 'number': 'LEC_002'}], 'subject': 'Computer Science'}, {'credits': 3, 'description': 'Focuses on the role that psychological principles, research evidence and social science play in the laws of U.S. society, especially in the policies and mechanisms of social control of human behavior. The course will address the ways that society defines membership, and the role of psychology in how it determines who should be excluded or restricted from open society, in order to maintain a more civil society. In addition to learning the factual information about how selected processes work in the legal and social context, students will be asked to consider the role they can play as citizens in supporting or changing these social processes. The course will take a particular interest in psycholegal issues \"in action\" and in learning about the clinical-legal processes used to determine the disposition of individuals considered marginal in society. Finally, the course will address the mechanisms that are used to exclude individuals from open society through criminal and civil court processes, the role of psychology as a science, and the role of psychologists as behavioral experts in criminal and civil courts, and in shaping social policies.', 'keywords': ['psychology', 'science', 'law', 'social', 'policy', 'behavior'], 'name': 'Psychology, Law, and Social Policy', 'number': 'PSYCH_401', 'requisites': [['PSYCH_202']], 'sections': [{'instructor': 'Gregory Van Rybroek', 'location': '121 Brogden Psychology Building', 'subsections': [], 'time': {'monday': '4:00pm - 5:15pm', 'wednesday': '4:00pm - 5:15pm'}, 'number': 'LEC_001'}], 'subject': 'Psychology'}, {'credits': 3, 'description': 'Basic concepts of logic, sets, partial order and other relations, and functions. Basic concepts of mathematics (definitions, proofs, sets, functions, and relations) with a focus on discrete structures: integers, bits, strings, trees, and graphs. Propositional logic, Boolean algebra, and predicate logic. Mathematical induction and recursion. Invariants and algorithmic correctness. Recurrences and asymptotic growth analysis. Fundamentals of counting.', 'keywords': ['computer', 'science', 'math', 'mathematics', 'discrete', 'logic', 'algorithm', 'algorithms'], 'name': 'Introduction To Discrete Mathematics', 'number': 'COMPSCI_240', 'requisites': [['MATH_221']], 'sections': [{'instructor': 'Beck Hasti', 'location': '105 Brogden Psychology Building', 'subsections': [{'location': '1257 Computer Sciences and Statistics', 'time': {'tuesday': '8:50am - 9:40am'}, 'number': 'DIS_310'}, {'location': '1257 Computer Sciences and Statistics', 'time': {'thursday': '8:50am - 9:40am'}, 'number': 'DIS_311'}, {'location': '3024 Engineering Hall', 'time': {'tuesday': '9:55am - 10:45am'}, 'number': 'DIS_312'}, {'location': '2345 Engineering Hall', 'time': {'thursday': '9:55am - 10:45am'}, 'number': 'DIS_313'}, {'location': '2535 Engineering Hall', 'time': {'tuesday': '11:00am - 11:50am'}, 'number': 'DIS_314'}, {'location': '2535 Engineering Hall', 'time': {'thursday': '11:00am - 11:50am'}, 'number': 'DIS_315'}, {'location': 'B309 Van Vleck Hall', 'time': {'tuesday': '9:55am - 10:45am'}, 'number': 'DIS_316'}], 'time': {'friday': '9:55am - 10:45am', 'monday': '9:55am - 10:45am', 'wednesday': '9:55am - 10:45am'}, 'number': 'LEC_001'}, {'instructor': 'Beck Hasti', 'location': '132 Noland Hall', 'subsections': [{'location': 'B211 Van Vleck Hall', 'time': {'thursday': '11:00am - 11:50am'}, 'number': 'DIS_320'}, {'location': 'B211 Van Vleck Hall', 'time': {'tuesday': '12:05pm - 12:55pm'}, 'number': 'DIS_321'}, {'location': '2255 Engineering Hall', 'time': {'thursday': '12:05pm - 12:55pm'}, 'number': 'DIS_322'}, {'location': '2349 Engineering Hall', 'time': {'tuesday': '1:20pm - 2:10pm'}, 'number': 'DIS_323'}, {'location': '1263 Computer Sciences and Statistics', 'time': {'thursday': '1:20pm - 2:10pm'}, 'number': 'DIS_324'}, {'location': '3418 Engineering Hall', 'time': {'tuesday': '2:25pm - 3:15pm'}, 'number': 'DIS_325'}, {'location': '3418 Engineering Hall', 'time': {'thursday': '2:25pm - 3:15pm'}, 'number': 'DIS_326'}], 'time': {'friday': '1:20pm - 2:10pm', 'monday': '1:20pm - 2:10pm', 'wednesday': '1:20pm - 2:10pm'}, 'number': 'LEC_002'}, {'instructor': 'Beck Hasti', 'location': '168 Noland Hall', 'subsections': [{'location': '1263 Computer Sciences and Statistics', 'time': {'tuesday': '8:50am - 9:40am'}, 'number': 'DIS_330'}, {'location': '1263 Computer Sciences and Statistics', 'time': {'tuesday': '1:20pm - 2:10pm'}, 'number': 'DIS_331'}, {'location': '3024 Engineering Hall', 'time': {'thursday': '9:55am - 10:45am'}, 'number': 'DIS_332'}, {'location': '2349 Engineering Hall', 'time': {'thursday': '12:05am - 12:55am'}, 'number': 'DIS_333'}], 'time': {'friday': '2:25pm - 3:15pm', 'monday': '2:25pm - 3:15pm', 'wednesday': '2:25pm - 3:15pm'}, 'number': 'LEC_003'}], 'subject': 'Computer Science'}, {'credits': 3, 'description': 'Graphical and numerical exploration of data; standard errors; distributions for statistical models including binomial, Poisson, normal; estimation; hypothesis testing; randomization tests; basic principles of experimental design; regression; ANOVA; categorical data analysis; goodness of fit; application. (intended for students wishing to take additional statistics courses).', 'keywords': ['statistics', 'statistical', 'math', 'mathematics', 'methods'], 'name': 'Accelerated Introduction to Statistical Methods', 'number': 'STATS_302', 'requisites': [['MATH_221']], 'sections': [{'instructor': 'Unknown', 'location': '331 Service Memorial Institute', 'subsections': [{'location': '212 Educational Sciences', 'time': {'tuesday': '1:20pm - 2:10pm'}, 'number': 'DIS_311'}, {'location': '1313 Sterling Hall', 'time': {'wednesday': '7:45am - 8:35am'}, 'number': 'DIS_312'}, {'location': '1313 Sterling Hall', 'time': {'wednesday': '11:00am - 11:50am'}, 'number': 'DIS_313'}], 'time': {'monday': '4:00pm - 5:15pm', 'wednesday': '4:00pm - 5:15pm'}, 'number': 'LEC_001'}], 'subject': 'Statistics'}]\n" - ] - } - ], - "source": [ - "# Collect all the class data in a list called 'all_class_data'\n", - "all_class_data = []\n", - "for class_num in classes_list:\n", - " url = \"https://coletnelson.us/cs220-api/classes/\" + class_num\n", - " r = requests.get(url)\n", - " r.raise_for_status()\n", - " class_data = r.json()\n", - " all_class_data.append(class_data)\n", - "\n", - "print(all_class_data) # Too much data? Try print(len(all_class_data))" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "17\n" - ] - } - ], - "source": [ - "print(len(all_class_data))" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3 PSYCH_202 Introduction to Psychology\n", - "4 COMPSCI_537 Introduction to Operating Systems\n", - "3 COMPSCI_300 Programming 2\n", - "5 CHEM_104 General Chemistry II\n", - "3 COMPSCI_200 Programming 1\n", - "5 MATH_114 Algebra and Trigonometry\n", - "4 PSYCH_456 Introductory Social Psychology\n", - "2 COMPSCI_252 Introduction to Computer Engineering\n", - "3 COMPSCI_400 Programming 3\n", - "5 MATH_221 Calculus and Analytical Geometry 1\n", - "3 BIOLOGY_101 Animal Biology\n", - "3 COMPSCI_354 Machine Organization and Programming\n", - "4 CHEM_103 General Chemistry I\n", - "3 COMPSCI_639 Building User Interfaces\n", - "3 PSYCH_401 Psychology, Law, and Social Policy\n", - "3 COMPSCI_240 Introduction To Discrete Mathematics\n", - "3 STATS_302 Accelerated Introduction to Statistical Methods\n" - ] - } - ], - "source": [ - "# Print the number of credits, course number, and name for each class.\n", - "for spec_class in all_class_data:\n", - " print(spec_class['credits'], spec_class['number'], spec_class['name'])" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3.4705882352941178" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# What is the average number of credits per course?\n", - "num_credits = 0 \n", - "for spec_class in all_class_data:\n", - " num_credits += spec_class['credits']\n", - "num_credits / len(all_class_data)" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['Computer Science',\n", - " 'Psychology',\n", - " 'Mathematics',\n", - " 'Statistics',\n", - " 'Biology',\n", - " 'Chemistry']" - ] - }, - "execution_count": 29, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# What are the unique subjects?\n", - "subjects = []\n", - "for spec_class in all_class_data:\n", - " subjects.append(spec_class['subject'])\n", - "list(set(subjects))" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['COMPSCI_300', 'COMPSCI_200', 'COMPSCI_400']" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Besides PYSCH 202, what are the course numbers of the courses\n", - "# with the most sections offered (not including subsections)?\n", - "high_courses = []\n", - "high_sections = 0\n", - "for spec_class in all_class_data:\n", - " current_course_num = spec_class['number']\n", - " current_num_sects = len(spec_class['sections'])\n", - " \n", - " if current_course_num == 'PSYCH_202':\n", - " continue\n", - " \n", - " if current_num_sects == high_sections:\n", - " high_courses.append(current_course_num)\n", - " elif current_num_sects > high_sections:\n", - " high_courses = []\n", - " high_courses.append(current_course_num)\n", - " high_sections = current_num_sects\n", - "high_courses" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Can we make a Pandas dataframe? Yes!" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>credits</th>\n", - " <th>description</th>\n", - " <th>keywords</th>\n", - " <th>name</th>\n", - " <th>number</th>\n", - " <th>requisites</th>\n", - " <th>sections</th>\n", - " <th>subject</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>3</td>\n", - " <td>Behavior, including its development, motivatio...</td>\n", - " <td>[psychology, behavior, emotion, intelligence, ...</td>\n", - " <td>Introduction to Psychology</td>\n", - " <td>PSYCH_202</td>\n", - " <td>[]</td>\n", - " <td>[{'instructor': 'Jeff Henriques', 'location': ...</td>\n", - " <td>Psychology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>4</td>\n", - " <td>Input-output hardware, interrupt handling, pro...</td>\n", - " <td>[computer, science, operating, system, systems]</td>\n", - " <td>Introduction to Operating Systems</td>\n", - " <td>COMPSCI_537</td>\n", - " <td>[[COMPSCI_354, COMPSCI_400]]</td>\n", - " <td>[{'instructor': 'Andrea Arpaci-Dusseau', 'loca...</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>3</td>\n", - " <td>Introduces students to Object-Oriented Program...</td>\n", - " <td>[computer, science, programming, java]</td>\n", - " <td>Programming 2</td>\n", - " <td>COMPSCI_300</td>\n", - " <td>[[COMPSCI_200]]</td>\n", - " <td>[{'instructor': 'Gary Dahl', 'location': 'AB20...</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>5</td>\n", - " <td>Principles and application of chemical equilib...</td>\n", - " <td>[chemistry]</td>\n", - " <td>General Chemistry II</td>\n", - " <td>CHEM_104</td>\n", - " <td>[[MATH_114], [CHEM_103]]</td>\n", - " <td>[{'instructor': 'Linda Zelewski', 'location': ...</td>\n", - " <td>Chemistry</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>3</td>\n", - " <td>Learn the process of incrementally developing ...</td>\n", - " <td>[computer, science, programming, java]</td>\n", - " <td>Programming 1</td>\n", - " <td>COMPSCI_200</td>\n", - " <td>[]</td>\n", - " <td>[{'instructor': 'Jim Williams', 'location': '1...</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>5</th>\n", - " <td>5</td>\n", - " <td>The two semester sequence MATH_112-MATH_113 co...</td>\n", - " <td>[math, mathematics, algebra, trigonometry]</td>\n", - " <td>Algebra and Trigonometry</td>\n", - " <td>MATH_114</td>\n", - " <td>[]</td>\n", - " <td>[{'instructor': 'Sharad Chandarana', 'location...</td>\n", - " <td>Mathematics</td>\n", - " </tr>\n", - " <tr>\n", - " <th>6</th>\n", - " <td>4</td>\n", - " <td>The systematic study of the individual in a so...</td>\n", - " <td>[psychology, science, social, interaction, beh...</td>\n", - " <td>Introductory Social Psychology</td>\n", - " <td>PSYCH_456</td>\n", - " <td>[[PSYCH_202]]</td>\n", - " <td>[{'instructor': 'Abigail Letak', 'location': '...</td>\n", - " <td>Psychology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>7</th>\n", - " <td>2</td>\n", - " <td>Logic components built with transistors, rudim...</td>\n", - " <td>[computer, science, engineering, programming]</td>\n", - " <td>Introduction to Computer Engineering</td>\n", - " <td>COMPSCI_252</td>\n", - " <td>[]</td>\n", - " <td>[{'instructor': 'Joseph Krachey', 'location': ...</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>8</th>\n", - " <td>3</td>\n", - " <td>The third course in our programming fundamenta...</td>\n", - " <td>[computer, science, programming, java]</td>\n", - " <td>Programming 3</td>\n", - " <td>COMPSCI_400</td>\n", - " <td>[[COMPSCI_300]]</td>\n", - " <td>[{'instructor': 'Gary Dahl', 'location': 'AB20...</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>9</th>\n", - " <td>5</td>\n", - " <td>Introduction to differential and integral calc...</td>\n", - " <td>[math, mathematics, calculus, analytical, geom...</td>\n", - " <td>Calculus and Analytical Geometry 1</td>\n", - " <td>MATH_221</td>\n", - " <td>[[MATH_114]]</td>\n", - " <td>[{'instructor': 'Laurentiu Maxim', 'location':...</td>\n", - " <td>Mathematics</td>\n", - " </tr>\n", - " <tr>\n", - " <th>10</th>\n", - " <td>3</td>\n", - " <td>General biological principles. Topics include:...</td>\n", - " <td>[biology, science, animal, evolution, genetics...</td>\n", - " <td>Animal Biology</td>\n", - " <td>BIOLOGY_101</td>\n", - " <td>[]</td>\n", - " <td>[{'instructor': 'Sharon Thoma', 'location': '2...</td>\n", - " <td>Biology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>11</th>\n", - " <td>3</td>\n", - " <td>An introduction to fundamental structures of c...</td>\n", - " <td>[computer, science, engineering, electrical, m...</td>\n", - " <td>Machine Organization and Programming</td>\n", - " <td>COMPSCI_354</td>\n", - " <td>[[COMPSCI_252], [COMPSCI_300]]</td>\n", - " <td>[{'instructor': 'James Skrentny', 'location': ...</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>12</th>\n", - " <td>4</td>\n", - " <td>Introduction. Stoichiometry and the mole conce...</td>\n", - " <td>[chemistry]</td>\n", - " <td>General Chemistry I</td>\n", - " <td>CHEM_103</td>\n", - " <td>[]</td>\n", - " <td>[{'instructor': 'Unknown', 'location': 'B10 In...</td>\n", - " <td>Chemistry</td>\n", - " </tr>\n", - " <tr>\n", - " <th>13</th>\n", - " <td>3</td>\n", - " <td>This course introduces students to the softwar...</td>\n", - " <td>[computer, science, building, user, interface,...</td>\n", - " <td>Building User Interfaces</td>\n", - " <td>COMPSCI_639</td>\n", - " <td>[[COMPSCI_300]]</td>\n", - " <td>[{'instructor': 'Bilge Mutlu', 'location': '12...</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>14</th>\n", - " <td>3</td>\n", - " <td>Focuses on the role that psychological princip...</td>\n", - " <td>[psychology, science, law, social, policy, beh...</td>\n", - " <td>Psychology, Law, and Social Policy</td>\n", - " <td>PSYCH_401</td>\n", - " <td>[[PSYCH_202]]</td>\n", - " <td>[{'instructor': 'Gregory Van Rybroek', 'locati...</td>\n", - " <td>Psychology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>15</th>\n", - " <td>3</td>\n", - " <td>Basic concepts of logic, sets, partial order a...</td>\n", - " <td>[computer, science, math, mathematics, discret...</td>\n", - " <td>Introduction To Discrete Mathematics</td>\n", - " <td>COMPSCI_240</td>\n", - " <td>[[MATH_221]]</td>\n", - " <td>[{'instructor': 'Beck Hasti', 'location': '105...</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>16</th>\n", - " <td>3</td>\n", - " <td>Graphical and numerical exploration of data; s...</td>\n", - " <td>[statistics, statistical, math, mathematics, m...</td>\n", - " <td>Accelerated Introduction to Statistical Methods</td>\n", - " <td>STATS_302</td>\n", - " <td>[[MATH_221]]</td>\n", - " <td>[{'instructor': 'Unknown', 'location': '331 Se...</td>\n", - " <td>Statistics</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "</div>" - ], - "text/plain": [ - " credits description \\\n", - "0 3 Behavior, including its development, motivatio... \n", - "1 4 Input-output hardware, interrupt handling, pro... \n", - "2 3 Introduces students to Object-Oriented Program... \n", - "3 5 Principles and application of chemical equilib... \n", - "4 3 Learn the process of incrementally developing ... \n", - "5 5 The two semester sequence MATH_112-MATH_113 co... \n", - "6 4 The systematic study of the individual in a so... \n", - "7 2 Logic components built with transistors, rudim... \n", - "8 3 The third course in our programming fundamenta... \n", - "9 5 Introduction to differential and integral calc... \n", - "10 3 General biological principles. Topics include:... \n", - "11 3 An introduction to fundamental structures of c... \n", - "12 4 Introduction. Stoichiometry and the mole conce... \n", - "13 3 This course introduces students to the softwar... \n", - "14 3 Focuses on the role that psychological princip... \n", - "15 3 Basic concepts of logic, sets, partial order a... \n", - "16 3 Graphical and numerical exploration of data; s... \n", - "\n", - " keywords \\\n", - "0 [psychology, behavior, emotion, intelligence, ... \n", - "1 [computer, science, operating, system, systems] \n", - "2 [computer, science, programming, java] \n", - "3 [chemistry] \n", - "4 [computer, science, programming, java] \n", - "5 [math, mathematics, algebra, trigonometry] \n", - "6 [psychology, science, social, interaction, beh... \n", - "7 [computer, science, engineering, programming] \n", - "8 [computer, science, programming, java] \n", - "9 [math, mathematics, calculus, analytical, geom... \n", - "10 [biology, science, animal, evolution, genetics... \n", - "11 [computer, science, engineering, electrical, m... \n", - "12 [chemistry] \n", - "13 [computer, science, building, user, interface,... \n", - "14 [psychology, science, law, social, policy, beh... \n", - "15 [computer, science, math, mathematics, discret... \n", - "16 [statistics, statistical, math, mathematics, m... \n", - "\n", - " name number \\\n", - "0 Introduction to Psychology PSYCH_202 \n", - "1 Introduction to Operating Systems COMPSCI_537 \n", - "2 Programming 2 COMPSCI_300 \n", - "3 General Chemistry II CHEM_104 \n", - "4 Programming 1 COMPSCI_200 \n", - "5 Algebra and Trigonometry MATH_114 \n", - "6 Introductory Social Psychology PSYCH_456 \n", - "7 Introduction to Computer Engineering COMPSCI_252 \n", - "8 Programming 3 COMPSCI_400 \n", - "9 Calculus and Analytical Geometry 1 MATH_221 \n", - "10 Animal Biology BIOLOGY_101 \n", - "11 Machine Organization and Programming COMPSCI_354 \n", - "12 General Chemistry I CHEM_103 \n", - "13 Building User Interfaces COMPSCI_639 \n", - "14 Psychology, Law, and Social Policy PSYCH_401 \n", - "15 Introduction To Discrete Mathematics COMPSCI_240 \n", - "16 Accelerated Introduction to Statistical Methods STATS_302 \n", - "\n", - " requisites \\\n", - "0 [] \n", - "1 [[COMPSCI_354, COMPSCI_400]] \n", - "2 [[COMPSCI_200]] \n", - "3 [[MATH_114], [CHEM_103]] \n", - "4 [] \n", - "5 [] \n", - "6 [[PSYCH_202]] \n", - "7 [] \n", - "8 [[COMPSCI_300]] \n", - "9 [[MATH_114]] \n", - "10 [] \n", - "11 [[COMPSCI_252], [COMPSCI_300]] \n", - "12 [] \n", - "13 [[COMPSCI_300]] \n", - "14 [[PSYCH_202]] \n", - "15 [[MATH_221]] \n", - "16 [[MATH_221]] \n", - "\n", - " sections subject \n", - "0 [{'instructor': 'Jeff Henriques', 'location': ... Psychology \n", - "1 [{'instructor': 'Andrea Arpaci-Dusseau', 'loca... Computer Science \n", - "2 [{'instructor': 'Gary Dahl', 'location': 'AB20... Computer Science \n", - "3 [{'instructor': 'Linda Zelewski', 'location': ... Chemistry \n", - "4 [{'instructor': 'Jim Williams', 'location': '1... Computer Science \n", - "5 [{'instructor': 'Sharad Chandarana', 'location... Mathematics \n", - "6 [{'instructor': 'Abigail Letak', 'location': '... Psychology \n", - "7 [{'instructor': 'Joseph Krachey', 'location': ... Computer Science \n", - "8 [{'instructor': 'Gary Dahl', 'location': 'AB20... Computer Science \n", - "9 [{'instructor': 'Laurentiu Maxim', 'location':... Mathematics \n", - "10 [{'instructor': 'Sharon Thoma', 'location': '2... Biology \n", - "11 [{'instructor': 'James Skrentny', 'location': ... Computer Science \n", - "12 [{'instructor': 'Unknown', 'location': 'B10 In... Chemistry \n", - "13 [{'instructor': 'Bilge Mutlu', 'location': '12... Computer Science \n", - "14 [{'instructor': 'Gregory Van Rybroek', 'locati... Psychology \n", - "15 [{'instructor': 'Beck Hasti', 'location': '105... Computer Science \n", - "16 [{'instructor': 'Unknown', 'location': '331 Se... Statistics " - ] - }, - "execution_count": 31, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "all_course_frame = DataFrame(all_class_data)\n", - "all_course_frame" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### We may want to do some \"plumbing\" with our data." - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>credits</th>\n", - " <th>description</th>\n", - " <th>keywords</th>\n", - " <th>name</th>\n", - " <th>number</th>\n", - " <th>subject</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>3</td>\n", - " <td>Behavior, including its development, motivatio...</td>\n", - " <td>[psychology, behavior, emotion, intelligence, ...</td>\n", - " <td>Introduction to Psychology</td>\n", - " <td>PSYCH_202</td>\n", - " <td>Psychology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>4</td>\n", - " <td>Input-output hardware, interrupt handling, pro...</td>\n", - " <td>[computer, science, operating, system, systems]</td>\n", - " <td>Introduction to Operating Systems</td>\n", - " <td>COMPSCI_537</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>3</td>\n", - " <td>Introduces students to Object-Oriented Program...</td>\n", - " <td>[computer, science, programming, java]</td>\n", - " <td>Programming 2</td>\n", - " <td>COMPSCI_300</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>5</td>\n", - " <td>Principles and application of chemical equilib...</td>\n", - " <td>[chemistry]</td>\n", - " <td>General Chemistry II</td>\n", - " <td>CHEM_104</td>\n", - " <td>Chemistry</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>3</td>\n", - " <td>Learn the process of incrementally developing ...</td>\n", - " <td>[computer, science, programming, java]</td>\n", - " <td>Programming 1</td>\n", - " <td>COMPSCI_200</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>5</th>\n", - " <td>5</td>\n", - " <td>The two semester sequence MATH_112-MATH_113 co...</td>\n", - " <td>[math, mathematics, algebra, trigonometry]</td>\n", - " <td>Algebra and Trigonometry</td>\n", - " <td>MATH_114</td>\n", - " <td>Mathematics</td>\n", - " </tr>\n", - " <tr>\n", - " <th>6</th>\n", - " <td>4</td>\n", - " <td>The systematic study of the individual in a so...</td>\n", - " <td>[psychology, science, social, interaction, beh...</td>\n", - " <td>Introductory Social Psychology</td>\n", - " <td>PSYCH_456</td>\n", - " <td>Psychology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>7</th>\n", - " <td>2</td>\n", - " <td>Logic components built with transistors, rudim...</td>\n", - " <td>[computer, science, engineering, programming]</td>\n", - " <td>Introduction to Computer Engineering</td>\n", - " <td>COMPSCI_252</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>8</th>\n", - " <td>3</td>\n", - " <td>The third course in our programming fundamenta...</td>\n", - " <td>[computer, science, programming, java]</td>\n", - " <td>Programming 3</td>\n", - " <td>COMPSCI_400</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>9</th>\n", - " <td>5</td>\n", - " <td>Introduction to differential and integral calc...</td>\n", - " <td>[math, mathematics, calculus, analytical, geom...</td>\n", - " <td>Calculus and Analytical Geometry 1</td>\n", - " <td>MATH_221</td>\n", - " <td>Mathematics</td>\n", - " </tr>\n", - " <tr>\n", - " <th>10</th>\n", - " <td>3</td>\n", - " <td>General biological principles. Topics include:...</td>\n", - " <td>[biology, science, animal, evolution, genetics...</td>\n", - " <td>Animal Biology</td>\n", - " <td>BIOLOGY_101</td>\n", - " <td>Biology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>11</th>\n", - " <td>3</td>\n", - " <td>An introduction to fundamental structures of c...</td>\n", - " <td>[computer, science, engineering, electrical, m...</td>\n", - " <td>Machine Organization and Programming</td>\n", - " <td>COMPSCI_354</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>12</th>\n", - " <td>4</td>\n", - " <td>Introduction. Stoichiometry and the mole conce...</td>\n", - " <td>[chemistry]</td>\n", - " <td>General Chemistry I</td>\n", - " <td>CHEM_103</td>\n", - " <td>Chemistry</td>\n", - " </tr>\n", - " <tr>\n", - " <th>13</th>\n", - " <td>3</td>\n", - " <td>This course introduces students to the softwar...</td>\n", - " <td>[computer, science, building, user, interface,...</td>\n", - " <td>Building User Interfaces</td>\n", - " <td>COMPSCI_639</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>14</th>\n", - " <td>3</td>\n", - " <td>Focuses on the role that psychological princip...</td>\n", - " <td>[psychology, science, law, social, policy, beh...</td>\n", - " <td>Psychology, Law, and Social Policy</td>\n", - " <td>PSYCH_401</td>\n", - " <td>Psychology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>15</th>\n", - " <td>3</td>\n", - " <td>Basic concepts of logic, sets, partial order a...</td>\n", - " <td>[computer, science, math, mathematics, discret...</td>\n", - " <td>Introduction To Discrete Mathematics</td>\n", - " <td>COMPSCI_240</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>16</th>\n", - " <td>3</td>\n", - " <td>Graphical and numerical exploration of data; s...</td>\n", - " <td>[statistics, statistical, math, mathematics, m...</td>\n", - " <td>Accelerated Introduction to Statistical Methods</td>\n", - " <td>STATS_302</td>\n", - " <td>Statistics</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "</div>" - ], - "text/plain": [ - " credits description \\\n", - "0 3 Behavior, including its development, motivatio... \n", - "1 4 Input-output hardware, interrupt handling, pro... \n", - "2 3 Introduces students to Object-Oriented Program... \n", - "3 5 Principles and application of chemical equilib... \n", - "4 3 Learn the process of incrementally developing ... \n", - "5 5 The two semester sequence MATH_112-MATH_113 co... \n", - "6 4 The systematic study of the individual in a so... \n", - "7 2 Logic components built with transistors, rudim... \n", - "8 3 The third course in our programming fundamenta... \n", - "9 5 Introduction to differential and integral calc... \n", - "10 3 General biological principles. Topics include:... \n", - "11 3 An introduction to fundamental structures of c... \n", - "12 4 Introduction. Stoichiometry and the mole conce... \n", - "13 3 This course introduces students to the softwar... \n", - "14 3 Focuses on the role that psychological princip... \n", - "15 3 Basic concepts of logic, sets, partial order a... \n", - "16 3 Graphical and numerical exploration of data; s... \n", - "\n", - " keywords \\\n", - "0 [psychology, behavior, emotion, intelligence, ... \n", - "1 [computer, science, operating, system, systems] \n", - "2 [computer, science, programming, java] \n", - "3 [chemistry] \n", - "4 [computer, science, programming, java] \n", - "5 [math, mathematics, algebra, trigonometry] \n", - "6 [psychology, science, social, interaction, beh... \n", - "7 [computer, science, engineering, programming] \n", - "8 [computer, science, programming, java] \n", - "9 [math, mathematics, calculus, analytical, geom... \n", - "10 [biology, science, animal, evolution, genetics... \n", - "11 [computer, science, engineering, electrical, m... \n", - "12 [chemistry] \n", - "13 [computer, science, building, user, interface,... \n", - "14 [psychology, science, law, social, policy, beh... \n", - "15 [computer, science, math, mathematics, discret... \n", - "16 [statistics, statistical, math, mathematics, m... \n", - "\n", - " name number \\\n", - "0 Introduction to Psychology PSYCH_202 \n", - "1 Introduction to Operating Systems COMPSCI_537 \n", - "2 Programming 2 COMPSCI_300 \n", - "3 General Chemistry II CHEM_104 \n", - "4 Programming 1 COMPSCI_200 \n", - "5 Algebra and Trigonometry MATH_114 \n", - "6 Introductory Social Psychology PSYCH_456 \n", - "7 Introduction to Computer Engineering COMPSCI_252 \n", - "8 Programming 3 COMPSCI_400 \n", - "9 Calculus and Analytical Geometry 1 MATH_221 \n", - "10 Animal Biology BIOLOGY_101 \n", - "11 Machine Organization and Programming COMPSCI_354 \n", - "12 General Chemistry I CHEM_103 \n", - "13 Building User Interfaces COMPSCI_639 \n", - "14 Psychology, Law, and Social Policy PSYCH_401 \n", - "15 Introduction To Discrete Mathematics COMPSCI_240 \n", - "16 Accelerated Introduction to Statistical Methods STATS_302 \n", - "\n", - " subject \n", - "0 Psychology \n", - "1 Computer Science \n", - "2 Computer Science \n", - "3 Chemistry \n", - "4 Computer Science \n", - "5 Mathematics \n", - "6 Psychology \n", - "7 Computer Science \n", - "8 Computer Science \n", - "9 Mathematics \n", - "10 Biology \n", - "11 Computer Science \n", - "12 Chemistry \n", - "13 Computer Science \n", - "14 Psychology \n", - "15 Computer Science \n", - "16 Statistics " - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Remove the 'sections' and 'requisites' column.\n", - "new_course_frame = all_course_frame.loc[:, \"credits\":\"number\"]\n", - "new_course_frame[\"subject\"] = all_course_frame.loc[:, \"subject\"]\n", - "new_course_frame" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>credits</th>\n", - " <th>description</th>\n", - " <th>keywords</th>\n", - " <th>name</th>\n", - " <th>number</th>\n", - " <th>subject</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>3</td>\n", - " <td>Behavior, including its development, motivatio...</td>\n", - " <td>psychology, behavior, emotion, intelligence, b...</td>\n", - " <td>Introduction to Psychology</td>\n", - " <td>PSYCH_202</td>\n", - " <td>Psychology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>4</td>\n", - " <td>Input-output hardware, interrupt handling, pro...</td>\n", - " <td>computer, science, operating, system, systems</td>\n", - " <td>Introduction to Operating Systems</td>\n", - " <td>COMPSCI_537</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>3</td>\n", - " <td>Introduces students to Object-Oriented Program...</td>\n", - " <td>computer, science, programming, java</td>\n", - " <td>Programming 2</td>\n", - " <td>COMPSCI_300</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>5</td>\n", - " <td>Principles and application of chemical equilib...</td>\n", - " <td>chemistry</td>\n", - " <td>General Chemistry II</td>\n", - " <td>CHEM_104</td>\n", - " <td>Chemistry</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>3</td>\n", - " <td>Learn the process of incrementally developing ...</td>\n", - " <td>computer, science, programming, java</td>\n", - " <td>Programming 1</td>\n", - " <td>COMPSCI_200</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>5</th>\n", - " <td>5</td>\n", - " <td>The two semester sequence MATH_112-MATH_113 co...</td>\n", - " <td>math, mathematics, algebra, trigonometry</td>\n", - " <td>Algebra and Trigonometry</td>\n", - " <td>MATH_114</td>\n", - " <td>Mathematics</td>\n", - " </tr>\n", - " <tr>\n", - " <th>6</th>\n", - " <td>4</td>\n", - " <td>The systematic study of the individual in a so...</td>\n", - " <td>psychology, science, social, interaction, beha...</td>\n", - " <td>Introductory Social Psychology</td>\n", - " <td>PSYCH_456</td>\n", - " <td>Psychology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>7</th>\n", - " <td>2</td>\n", - " <td>Logic components built with transistors, rudim...</td>\n", - " <td>computer, science, engineering, programming</td>\n", - " <td>Introduction to Computer Engineering</td>\n", - " <td>COMPSCI_252</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>8</th>\n", - " <td>3</td>\n", - " <td>The third course in our programming fundamenta...</td>\n", - " <td>computer, science, programming, java</td>\n", - " <td>Programming 3</td>\n", - " <td>COMPSCI_400</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>9</th>\n", - " <td>5</td>\n", - " <td>Introduction to differential and integral calc...</td>\n", - " <td>math, mathematics, calculus, analytical, geome...</td>\n", - " <td>Calculus and Analytical Geometry 1</td>\n", - " <td>MATH_221</td>\n", - " <td>Mathematics</td>\n", - " </tr>\n", - " <tr>\n", - " <th>10</th>\n", - " <td>3</td>\n", - " <td>General biological principles. Topics include:...</td>\n", - " <td>biology, science, animal, evolution, genetics,...</td>\n", - " <td>Animal Biology</td>\n", - " <td>BIOLOGY_101</td>\n", - " <td>Biology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>11</th>\n", - " <td>3</td>\n", - " <td>An introduction to fundamental structures of c...</td>\n", - " <td>computer, science, engineering, electrical, ma...</td>\n", - " <td>Machine Organization and Programming</td>\n", - " <td>COMPSCI_354</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>12</th>\n", - " <td>4</td>\n", - " <td>Introduction. Stoichiometry and the mole conce...</td>\n", - " <td>chemistry</td>\n", - " <td>General Chemistry I</td>\n", - " <td>CHEM_103</td>\n", - " <td>Chemistry</td>\n", - " </tr>\n", - " <tr>\n", - " <th>13</th>\n", - " <td>3</td>\n", - " <td>This course introduces students to the softwar...</td>\n", - " <td>computer, science, building, user, interface, ...</td>\n", - " <td>Building User Interfaces</td>\n", - " <td>COMPSCI_639</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>14</th>\n", - " <td>3</td>\n", - " <td>Focuses on the role that psychological princip...</td>\n", - " <td>psychology, science, law, social, policy, beha...</td>\n", - " <td>Psychology, Law, and Social Policy</td>\n", - " <td>PSYCH_401</td>\n", - " <td>Psychology</td>\n", - " </tr>\n", - " <tr>\n", - " <th>15</th>\n", - " <td>3</td>\n", - " <td>Basic concepts of logic, sets, partial order a...</td>\n", - " <td>computer, science, math, mathematics, discrete...</td>\n", - " <td>Introduction To Discrete Mathematics</td>\n", - " <td>COMPSCI_240</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>16</th>\n", - " <td>3</td>\n", - " <td>Graphical and numerical exploration of data; s...</td>\n", - " <td>statistics, statistical, math, mathematics, me...</td>\n", - " <td>Accelerated Introduction to Statistical Methods</td>\n", - " <td>STATS_302</td>\n", - " <td>Statistics</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "</div>" - ], - "text/plain": [ - " credits description \\\n", - "0 3 Behavior, including its development, motivatio... \n", - "1 4 Input-output hardware, interrupt handling, pro... \n", - "2 3 Introduces students to Object-Oriented Program... \n", - "3 5 Principles and application of chemical equilib... \n", - "4 3 Learn the process of incrementally developing ... \n", - "5 5 The two semester sequence MATH_112-MATH_113 co... \n", - "6 4 The systematic study of the individual in a so... \n", - "7 2 Logic components built with transistors, rudim... \n", - "8 3 The third course in our programming fundamenta... \n", - "9 5 Introduction to differential and integral calc... \n", - "10 3 General biological principles. Topics include:... \n", - "11 3 An introduction to fundamental structures of c... \n", - "12 4 Introduction. Stoichiometry and the mole conce... \n", - "13 3 This course introduces students to the softwar... \n", - "14 3 Focuses on the role that psychological princip... \n", - "15 3 Basic concepts of logic, sets, partial order a... \n", - "16 3 Graphical and numerical exploration of data; s... \n", - "\n", - " keywords \\\n", - "0 psychology, behavior, emotion, intelligence, b... \n", - "1 computer, science, operating, system, systems \n", - "2 computer, science, programming, java \n", - "3 chemistry \n", - "4 computer, science, programming, java \n", - "5 math, mathematics, algebra, trigonometry \n", - "6 psychology, science, social, interaction, beha... \n", - "7 computer, science, engineering, programming \n", - "8 computer, science, programming, java \n", - "9 math, mathematics, calculus, analytical, geome... \n", - "10 biology, science, animal, evolution, genetics,... \n", - "11 computer, science, engineering, electrical, ma... \n", - "12 chemistry \n", - "13 computer, science, building, user, interface, ... \n", - "14 psychology, science, law, social, policy, beha... \n", - "15 computer, science, math, mathematics, discrete... \n", - "16 statistics, statistical, math, mathematics, me... \n", - "\n", - " name number \\\n", - "0 Introduction to Psychology PSYCH_202 \n", - "1 Introduction to Operating Systems COMPSCI_537 \n", - "2 Programming 2 COMPSCI_300 \n", - "3 General Chemistry II CHEM_104 \n", - "4 Programming 1 COMPSCI_200 \n", - "5 Algebra and Trigonometry MATH_114 \n", - "6 Introductory Social Psychology PSYCH_456 \n", - "7 Introduction to Computer Engineering COMPSCI_252 \n", - "8 Programming 3 COMPSCI_400 \n", - "9 Calculus and Analytical Geometry 1 MATH_221 \n", - "10 Animal Biology BIOLOGY_101 \n", - "11 Machine Organization and Programming COMPSCI_354 \n", - "12 General Chemistry I CHEM_103 \n", - "13 Building User Interfaces COMPSCI_639 \n", - "14 Psychology, Law, and Social Policy PSYCH_401 \n", - "15 Introduction To Discrete Mathematics COMPSCI_240 \n", - "16 Accelerated Introduction to Statistical Methods STATS_302 \n", - "\n", - " subject \n", - "0 Psychology \n", - "1 Computer Science \n", - "2 Computer Science \n", - "3 Chemistry \n", - "4 Computer Science \n", - "5 Mathematics \n", - "6 Psychology \n", - "7 Computer Science \n", - "8 Computer Science \n", - "9 Mathematics \n", - "10 Biology \n", - "11 Computer Science \n", - "12 Chemistry \n", - "13 Computer Science \n", - "14 Psychology \n", - "15 Computer Science \n", - "16 Statistics " - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Turn 'keywords' into a series of Strings and remove the '[', ']', '''\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].astype('string')\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].str.replace(\"[\", \"\", regex=False)\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].str.replace(\"]\", \"\", regex=False)\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].str.replace(\"'\", \"\", regex=False)\n", - "new_course_frame" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Pandas Operations" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# What is the most number of credits a course offers?\n", - "new_course_frame[\"credits\"].max()" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "2" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# What is the least number of credits a course offers?\n", - "new_course_frame[\"credits\"].min()" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "credits 2\n", - "description Logic components built with transistors, rudim...\n", - "keywords computer, science, engineering, programming\n", - "name Introduction to Computer Engineering\n", - "number COMPSCI_252\n", - "subject Computer Science\n", - "Name: 7, dtype: object" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# What is the info for that course?\n", - "new_course_frame.iloc[new_course_frame[\"credits\"].idxmin()]" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>credits</th>\n", - " <th>description</th>\n", - " <th>keywords</th>\n", - " <th>name</th>\n", - " <th>number</th>\n", - " <th>subject</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>3</td>\n", - " <td>Introduces students to Object-Oriented Program...</td>\n", - " <td>computer, science, programming, java</td>\n", - " <td>Programming 2</td>\n", - " <td>COMPSCI_300</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>3</td>\n", - " <td>Learn the process of incrementally developing ...</td>\n", - " <td>computer, science, programming, java</td>\n", - " <td>Programming 1</td>\n", - " <td>COMPSCI_200</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>7</th>\n", - " <td>2</td>\n", - " <td>Logic components built with transistors, rudim...</td>\n", - " <td>computer, science, engineering, programming</td>\n", - " <td>Introduction to Computer Engineering</td>\n", - " <td>COMPSCI_252</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>8</th>\n", - " <td>3</td>\n", - " <td>The third course in our programming fundamenta...</td>\n", - " <td>computer, science, programming, java</td>\n", - " <td>Programming 3</td>\n", - " <td>COMPSCI_400</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " <tr>\n", - " <th>11</th>\n", - " <td>3</td>\n", - " <td>An introduction to fundamental structures of c...</td>\n", - " <td>computer, science, engineering, electrical, ma...</td>\n", - " <td>Machine Organization and Programming</td>\n", - " <td>COMPSCI_354</td>\n", - " <td>Computer Science</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "</div>" - ], - "text/plain": [ - " credits description \\\n", - "2 3 Introduces students to Object-Oriented Program... \n", - "4 3 Learn the process of incrementally developing ... \n", - "7 2 Logic components built with transistors, rudim... \n", - "8 3 The third course in our programming fundamenta... \n", - "11 3 An introduction to fundamental structures of c... \n", - "\n", - " keywords \\\n", - "2 computer, science, programming, java \n", - "4 computer, science, programming, java \n", - "7 computer, science, engineering, programming \n", - "8 computer, science, programming, java \n", - "11 computer, science, engineering, electrical, ma... \n", - "\n", - " name number subject \n", - "2 Programming 2 COMPSCI_300 Computer Science \n", - "4 Programming 1 COMPSCI_200 Computer Science \n", - "7 Introduction to Computer Engineering COMPSCI_252 Computer Science \n", - "8 Programming 3 COMPSCI_400 Computer Science \n", - "11 Machine Organization and Programming COMPSCI_354 Computer Science " - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# What courses contain the keyword \"programming\"?\n", - "mask = new_course_frame[\"keywords\"].str.contains(\"programming\")\n", - "new_course_frame[mask]" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Psychology, Law, and Social Policy'" - ] - }, - "execution_count": 38, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# What course has the most lengthy description?\n", - "idx_max_desc = new_course_frame[\"description\"].str.len().idxmax()\n", - "new_course_frame.iloc[idx_max_desc]['name']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Write it out to a CSV file on your drive\n", - "You now have your own copy!" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": {}, - "outputs": [], - "source": [ - "# Write it all out to a single CSV file\n", - "new_course_frame.to_csv(\"my_course_data.csv\", index=False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Other Cool APIs" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- City of Madison Transit: http://transitdata.cityofmadison.com/\n", - "- Reddit: https://reddit.com/r/UWMadison.json\n", - "- Lord of the Rings: https://the-one-api.dev/\n", - "- Pokemon: https://pokeapi.co/\n", - "\n", - "Remember: Be judicious when making requests; don't overwhelm the server! :)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Next Time\n", - "What other documents can we get via the Web? HTML is very popular! We'll explore this." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.1" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/f22/andy_lec_notes/lec29_Nov16_Web1/CS220_Lec29_Sec004_Template.ipynb b/f22/andy_lec_notes/lec29_Nov16_Web1/CS220_Lec29_Sec004_Template.ipynb deleted file mode 100644 index c07f7e2b72c4d9582e8489026a91a25e3950a4d2..0000000000000000000000000000000000000000 --- a/f22/andy_lec_notes/lec29_Nov16_Web1/CS220_Lec29_Sec004_Template.ipynb +++ /dev/null @@ -1,668 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "import requests # We will learn about this today!\n", - "import json\n", - "import pandas as pd\n", - "from pandas import Series, DataFrame" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Warmup 1: Read the data from \"new_movie_data.csv\" into a pandas DataFrame called \"movies\"\n", - "movies = None\n", - "movies" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " to \n" - ] - } - ], - "source": [ - "# Warmup 2: What years does this new movie dataset cover? (min and max?)\n", - "\n", - "print(\"\", \"to\", \"\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Warmup 3a: What does this function do?\n", - "def format_revenue(revenue):\n", - " if type(revenue) == float: # need this in here if we run code multiple times\n", - " return revenue\n", - " elif revenue[-1] == 'M': # some have an \"M\" at the end\n", - " return float(revenue[:-1]) * 1e6\n", - " else: # otherwise, assume millions.\n", - " return float(revenue) * 1e6" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Warmup 3b: Using the above function, create a new column called\n", - "# \"CountableRevenue\" with the revenue as a float.\n", - "\n", - "movies[\"CountableRevenue\"] = None\n", - "movies" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Warmup 4: What are the top 10 highest-revenue movies?\n", - "\n", - "movies.sort_values().head(10)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Lecture 29: Web 1 - Getting Data\n", - "Learning Objectives\n", - "\n", - "- Make a request for data using `requests.get(URL)`\n", - "- Check the status of a request/response\n", - "- Extract the text of a response\n", - "- Create a json file from a response\n", - "- State and practice good etiquette when getting data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Make a request for data using `requests.get(URL)`\n", - "- URL: https://www.msyamkumar.com/hello.txt" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "url = \"https://www.msyamkumar.com/hello.txt\"\n", - "r = requests.get(url) # r is the response\n", - "print(r.status_code)\n", - "print(r.text)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### HTTP Status Codes you need to know\n", - "\n", - "- 200: success\n", - "- 404: not found\n", - "\n", - "Here is a list of all status codes, you do NOT need to memorize it\n", - "\n", - "https://en.wikipedia.org/wiki/List_of_HTTP_status_codes" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Q: What if the web site does not exist?\n", - "typo_url = \"https://www.msyamkumar.com/hello.txttttt\"\n", - "r = requests.get(typo_url)\n", - "print(r.status_code)\n", - "print(r.text)\n", - "\n", - "# A: We get a 404 (client error)\n", - "# A: we get text, but the text is not from the client" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Check the status of a request/response\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# We can check for a status_code error by using an assert\n", - "typo_url = \"https://www.msyamkumar.com/hello.txttttt\"\n", - "r = requests.get(typo_url)\n", - "print(r.status_code)\n", - "assert True # change this\n", - "\n", - "print(r.text)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Instead of using an assert, we often use raise_for_status()\n", - "r = requests.get(typo_url)\n", - "r.raise_for_status() #similar to asserting r.status_code == 200\n", - "r.text\n", - "\n", - "# Note the error you get.... We will use this in the next cell" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's try to catch that error\n", - "\n", - "try:\n", - "\n", - "except:\n", - " print(\"oops!!\", e)\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# we often need to prepend the names of exceptions with the name of the module\n", - "# fix the error from above\n", - "\n", - "try:\n", - "\n", - "except:\n", - " print(\"oops!!\", e)\n", - " \n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create a json file from a response\n", - "\n", - "- URL: https://www.msyamkumar.com/scores.json\n", - "- `json.load` (FILE_OBJECT)\n", - "- `json.loads` (STRING)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# GETting a JSON file, the long way\n", - "url = \"https://www.msyamkumar.com/scores.json\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "urltext = r.text\n", - "print(urltext)\n", - "d = json.loads(urltext)\n", - "print(type(d), d)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# GETting a JSON file, the shortcut way\n", - "url = \"https://www.msyamkumar.com/scores.json\"\n", - "#Shortcut to bypass using json.loads()\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "d2 = r.json()\n", - "print(type(d2), d2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Good GET Etiquette\n", - "\n", - "Don't make a lot of requests to the same server all at once.\n", - " - Requests use up the server's time\n", - " - Major websites will often ban users who make too many requests\n", - " - You can break a server....similar to DDoS attacks (DON'T DO THIS)\n", - " \n", - "In CS220 we will usually give you a link to a copied file to avoid overloading the site.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## DEMO: Course Enrollment" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Explore the API!\n", - "\n", - "https://coletnelson.us/cs220-api/classes\n", - "\n", - "https://coletnelson.us/cs220-api/classes_as_txt\n", - "\n", - "https://coletnelson.us/cs220-api/classes/MATH_221\n", - "\n", - "https://coletnelson.us/cs220-api/classes/COMPSCI_200\n", - "\n", - "... etc\n", - "\n", - "https://coletnelson.us/cs220-api/all_data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Get the list of classes." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### When the data is `json`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "url = \"https://coletnelson.us/cs220-api/classes\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "classes_list = None # what goes here? \n", - "print(type(classes_list))\n", - "print(classes_list)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### When the data is `text`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "url = \"https://coletnelson.us/cs220-api/classes_as_txt\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "classes_txt = None # what goes here? \n", - "print(type(classes_txt))\n", - "print(classes_txt)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "classes_txt_as_list = ???" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Get data for a specific class" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "url = \"https://coletnelson.us/cs220-api/classes/COMPSCI_200\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "cs200_data = r.json()\n", - "print(type(cs200_data))\n", - "print(cs200_data) # Too much data? Try print(cs220_data.keys())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cs200_data.keys()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Get the number of credits the course is worth\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Get the list of keywords for the course\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Get the official course name\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Get the number of sections offered.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Collect all the class data in a list called 'all_class_data'\n", - "all_class_data = []\n", - "for class_num in classes_list:\n", - " url = \"https://coletnelson.us/cs220-api/classes/\" + ???\n", - " r = requests.get(url)\n", - " r.raise_for_status()\n", - " class_data = r.json()\n", - " all_class_data.append(???)\n", - "\n", - "print(all_class_data) # Too much data? Try print(len(all_class_data))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(len(all_class_data))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Print the number of credits, course number, and name for each class.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What is the average number of credits per course?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What are the unique subjects?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Besides PYSCH 202, what are the course numbers of the courses\n", - "# with the most sections offered (not including subsections)?\n", - "high_courses = []\n", - "high_sections = 0\n", - "for spec_class in all_class_data:\n", - " pass\n", - "high_courses" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Can we make a Pandas dataframe? Yes!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "all_course_frame = DataFrame(all_class_data)\n", - "all_course_frame" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### We may want to do some \"plumbing\" with our data." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Remove the 'sections' and 'requisites' column.\n", - "new_course_frame = all_course_frame.loc[:, \"credits\":\"number\"]\n", - "new_course_frame[\"subject\"] = all_course_frame.loc[:, \"subject\"]\n", - "new_course_frame" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Turn 'keywords' into a series of Strings and remove the '[', ']', '''\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].astype('string')\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].str.replace(\"[\", \"\", regex=False)\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].str.replace(\"]\", \"\", regex=False)\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].str.replace(\"'\", \"\", regex=False)\n", - "new_course_frame" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Pandas Operations" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What is the most number of credits a course offers?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What is the least number of credits a course offers?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What is the info for that course?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What courses contain the keyword \"programming\"?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What course has the most lengthy description?\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Write it out to a CSV file on your drive\n", - "You now have your own copy!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Write it all out to a single CSV file\n", - "new_course_frame.to_csv(\"my_course_data.csv\", index=False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Other Cool APIs" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- City of Madison Transit: http://transitdata.cityofmadison.com/\n", - "- Reddit: https://reddit.com/r/UWMadison.json\n", - "- Lord of the Rings: https://the-one-api.dev/\n", - "- Pokemon: https://pokeapi.co/\n", - "\n", - "Remember: Be judicious when making requests; don't overwhelm the server! :)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Next Time\n", - "What other documents can we get via the Web? HTML is very popular! We'll explore this." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.1" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/f22/andy_lec_notes/lec29_Nov16_Web1/CS220_Lec29_Sec004_amfam.ipynb b/f22/andy_lec_notes/lec29_Nov16_Web1/CS220_Lec29_Sec004_amfam.ipynb deleted file mode 100644 index 1f84281fd15f05da4f03dafe320cd222bd1f692f..0000000000000000000000000000000000000000 --- a/f22/andy_lec_notes/lec29_Nov16_Web1/CS220_Lec29_Sec004_amfam.ipynb +++ /dev/null @@ -1,1556 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "import requests # We will learn about this today!\n", - "import json\n", - "import pandas as pd\n", - "from pandas import Series, DataFrame" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>Title</th>\n", - " <th>Genre</th>\n", - " <th>Director</th>\n", - " <th>Cast</th>\n", - " <th>Year</th>\n", - " <th>Runtime</th>\n", - " <th>Rating</th>\n", - " <th>Revenue</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>Guardians of the Galaxy</td>\n", - " <td>Action,Adventure,Sci-Fi</td>\n", - " <td>James Gunn</td>\n", - " <td>Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...</td>\n", - " <td>2014</td>\n", - " <td>121</td>\n", - " <td>8.1</td>\n", - " <td>333.13</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>Prometheus</td>\n", - " <td>Adventure,Mystery,Sci-Fi</td>\n", - " <td>Ridley Scott</td>\n", - " <td>Noomi Rapace, Logan Marshall-Green, Michael ...</td>\n", - " <td>2012</td>\n", - " <td>124</td>\n", - " <td>7.0</td>\n", - " <td>126.46M</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>Split</td>\n", - " <td>Horror,Thriller</td>\n", - " <td>M. Night Shyamalan</td>\n", - " <td>James McAvoy, Anya Taylor-Joy, Haley Lu Richar...</td>\n", - " <td>2016</td>\n", - " <td>117</td>\n", - " <td>7.3</td>\n", - " <td>138.12M</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>Sing</td>\n", - " <td>Animation,Comedy,Family</td>\n", - " <td>Christophe Lourdelet</td>\n", - " <td>Matthew McConaughey,Reese Witherspoon, Seth Ma...</td>\n", - " <td>2016</td>\n", - " <td>108</td>\n", - " <td>7.2</td>\n", - " <td>270.32</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>Suicide Squad</td>\n", - " <td>Action,Adventure,Fantasy</td>\n", - " <td>David Ayer</td>\n", - " <td>Will Smith, Jared Leto, Margot Robbie, Viola D...</td>\n", - " <td>2016</td>\n", - " <td>123</td>\n", - " <td>6.2</td>\n", - " <td>325.02</td>\n", - " </tr>\n", - " <tr>\n", - " <th>...</th>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1063</th>\n", - " <td>Guardians of the Galaxy Vol. 2</td>\n", - " <td>Action, Adventure, Comedy</td>\n", - " <td>James Gunn</td>\n", - " <td>Chris Pratt, Zoe Saldana, Dave Bautista, Vin D...</td>\n", - " <td>2017</td>\n", - " <td>136</td>\n", - " <td>7.6</td>\n", - " <td>389.81</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1064</th>\n", - " <td>Baby Driver</td>\n", - " <td>Action, Crime, Drama</td>\n", - " <td>Edgar Wright</td>\n", - " <td>Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon...</td>\n", - " <td>2017</td>\n", - " <td>113</td>\n", - " <td>7.6</td>\n", - " <td>107.83</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1065</th>\n", - " <td>Only the Brave</td>\n", - " <td>Action, Biography, Drama</td>\n", - " <td>Joseph Kosinski</td>\n", - " <td>Josh Brolin, Miles Teller, Jeff Bridges, Jenni...</td>\n", - " <td>2017</td>\n", - " <td>134</td>\n", - " <td>7.6</td>\n", - " <td>18.34</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1066</th>\n", - " <td>Incredibles 2</td>\n", - " <td>Animation, Action, Adventure</td>\n", - " <td>Brad Bird</td>\n", - " <td>Craig T. Nelson, Holly Hunter, Sarah Vowell, H...</td>\n", - " <td>2018</td>\n", - " <td>118</td>\n", - " <td>7.6</td>\n", - " <td>608.58</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1067</th>\n", - " <td>A Star Is Born</td>\n", - " <td>Drama, Music, Romance</td>\n", - " <td>Bradley Cooper</td>\n", - " <td>Lady Gaga, Bradley Cooper, Sam Elliott, Greg G...</td>\n", - " <td>2018</td>\n", - " <td>136</td>\n", - " <td>7.6</td>\n", - " <td>215.29</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "<p>1068 rows × 8 columns</p>\n", - "</div>" - ], - "text/plain": [ - " Title Genre \\\n", - "0 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", - "1 Prometheus Adventure,Mystery,Sci-Fi \n", - "2 Split Horror,Thriller \n", - "3 Sing Animation,Comedy,Family \n", - "4 Suicide Squad Action,Adventure,Fantasy \n", - "... ... ... \n", - "1063 Guardians of the Galaxy Vol. 2 Action, Adventure, Comedy \n", - "1064 Baby Driver Action, Crime, Drama \n", - "1065 Only the Brave Action, Biography, Drama \n", - "1066 Incredibles 2 Animation, Action, Adventure \n", - "1067 A Star Is Born Drama, Music, Romance \n", - "\n", - " Director Cast \\\n", - "0 James Gunn Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... \n", - "1 Ridley Scott Noomi Rapace, Logan Marshall-Green, Michael ... \n", - "2 M. Night Shyamalan James McAvoy, Anya Taylor-Joy, Haley Lu Richar... \n", - "3 Christophe Lourdelet Matthew McConaughey,Reese Witherspoon, Seth Ma... \n", - "4 David Ayer Will Smith, Jared Leto, Margot Robbie, Viola D... \n", - "... ... ... \n", - "1063 James Gunn Chris Pratt, Zoe Saldana, Dave Bautista, Vin D... \n", - "1064 Edgar Wright Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon... \n", - "1065 Joseph Kosinski Josh Brolin, Miles Teller, Jeff Bridges, Jenni... \n", - "1066 Brad Bird Craig T. Nelson, Holly Hunter, Sarah Vowell, H... \n", - "1067 Bradley Cooper Lady Gaga, Bradley Cooper, Sam Elliott, Greg G... \n", - "\n", - " Year Runtime Rating Revenue \n", - "0 2014 121 8.1 333.13 \n", - "1 2012 124 7.0 126.46M \n", - "2 2016 117 7.3 138.12M \n", - "3 2016 108 7.2 270.32 \n", - "4 2016 123 6.2 325.02 \n", - "... ... ... ... ... \n", - "1063 2017 136 7.6 389.81 \n", - "1064 2017 113 7.6 107.83 \n", - "1065 2017 134 7.6 18.34 \n", - "1066 2018 118 7.6 608.58 \n", - "1067 2018 136 7.6 215.29 \n", - "\n", - "[1068 rows x 8 columns]" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Warmup 1: Read the data from \"new_movie_data.csv\" into a pandas DataFrame called \"movies\"\n", - "movies = pd.read_csv(\"new_movie_data.csv\")\n", - "movies" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2006 to 2020\n" - ] - } - ], - "source": [ - "# Warmup 2: What years does this new movie dataset cover? (min and max?)\n", - "movies[\"Year\"]\n", - "print(movies[\"Year\"].min(), \"to\", movies[\"Year\"].max())" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "17300000.0" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Warmup 3a: What does this function do?\n", - "def format_revenue(revenue):\n", - " if type(revenue) == float: # need this in here if we run code multiple times\n", - " return revenue\n", - " elif revenue[-1] == 'M': # some have an \"M\" at the end\n", - " return float(revenue[:-1]) * 1e6\n", - " else: # otherwise, assume millions.\n", - " return float(revenue) * 1e6\n", - "format_revenue(\"17.3\")" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>Title</th>\n", - " <th>Genre</th>\n", - " <th>Director</th>\n", - " <th>Cast</th>\n", - " <th>Year</th>\n", - " <th>Runtime</th>\n", - " <th>Rating</th>\n", - " <th>Revenue</th>\n", - " <th>CountableRevenue</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>Guardians of the Galaxy</td>\n", - " <td>Action,Adventure,Sci-Fi</td>\n", - " <td>James Gunn</td>\n", - " <td>Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...</td>\n", - " <td>2014</td>\n", - " <td>121</td>\n", - " <td>8.1</td>\n", - " <td>333.13</td>\n", - " <td>333130000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>Prometheus</td>\n", - " <td>Adventure,Mystery,Sci-Fi</td>\n", - " <td>Ridley Scott</td>\n", - " <td>Noomi Rapace, Logan Marshall-Green, Michael ...</td>\n", - " <td>2012</td>\n", - " <td>124</td>\n", - " <td>7.0</td>\n", - " <td>126.46M</td>\n", - " <td>126460000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>Split</td>\n", - " <td>Horror,Thriller</td>\n", - " <td>M. Night Shyamalan</td>\n", - " <td>James McAvoy, Anya Taylor-Joy, Haley Lu Richar...</td>\n", - " <td>2016</td>\n", - " <td>117</td>\n", - " <td>7.3</td>\n", - " <td>138.12M</td>\n", - " <td>138120000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>Sing</td>\n", - " <td>Animation,Comedy,Family</td>\n", - " <td>Christophe Lourdelet</td>\n", - " <td>Matthew McConaughey,Reese Witherspoon, Seth Ma...</td>\n", - " <td>2016</td>\n", - " <td>108</td>\n", - " <td>7.2</td>\n", - " <td>270.32</td>\n", - " <td>270320000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>Suicide Squad</td>\n", - " <td>Action,Adventure,Fantasy</td>\n", - " <td>David Ayer</td>\n", - " <td>Will Smith, Jared Leto, Margot Robbie, Viola D...</td>\n", - " <td>2016</td>\n", - " <td>123</td>\n", - " <td>6.2</td>\n", - " <td>325.02</td>\n", - " <td>325020000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>...</th>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1063</th>\n", - " <td>Guardians of the Galaxy Vol. 2</td>\n", - " <td>Action, Adventure, Comedy</td>\n", - " <td>James Gunn</td>\n", - " <td>Chris Pratt, Zoe Saldana, Dave Bautista, Vin D...</td>\n", - " <td>2017</td>\n", - " <td>136</td>\n", - " <td>7.6</td>\n", - " <td>389.81</td>\n", - " <td>389810000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1064</th>\n", - " <td>Baby Driver</td>\n", - " <td>Action, Crime, Drama</td>\n", - " <td>Edgar Wright</td>\n", - " <td>Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon...</td>\n", - " <td>2017</td>\n", - " <td>113</td>\n", - " <td>7.6</td>\n", - " <td>107.83</td>\n", - " <td>107830000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1065</th>\n", - " <td>Only the Brave</td>\n", - " <td>Action, Biography, Drama</td>\n", - " <td>Joseph Kosinski</td>\n", - " <td>Josh Brolin, Miles Teller, Jeff Bridges, Jenni...</td>\n", - " <td>2017</td>\n", - " <td>134</td>\n", - " <td>7.6</td>\n", - " <td>18.34</td>\n", - " <td>18340000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1066</th>\n", - " <td>Incredibles 2</td>\n", - " <td>Animation, Action, Adventure</td>\n", - " <td>Brad Bird</td>\n", - " <td>Craig T. Nelson, Holly Hunter, Sarah Vowell, H...</td>\n", - " <td>2018</td>\n", - " <td>118</td>\n", - " <td>7.6</td>\n", - " <td>608.58</td>\n", - " <td>608580000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1067</th>\n", - " <td>A Star Is Born</td>\n", - " <td>Drama, Music, Romance</td>\n", - " <td>Bradley Cooper</td>\n", - " <td>Lady Gaga, Bradley Cooper, Sam Elliott, Greg G...</td>\n", - " <td>2018</td>\n", - " <td>136</td>\n", - " <td>7.6</td>\n", - " <td>215.29</td>\n", - " <td>215290000.0</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "<p>1068 rows × 9 columns</p>\n", - "</div>" - ], - "text/plain": [ - " Title Genre \\\n", - "0 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", - "1 Prometheus Adventure,Mystery,Sci-Fi \n", - "2 Split Horror,Thriller \n", - "3 Sing Animation,Comedy,Family \n", - "4 Suicide Squad Action,Adventure,Fantasy \n", - "... ... ... \n", - "1063 Guardians of the Galaxy Vol. 2 Action, Adventure, Comedy \n", - "1064 Baby Driver Action, Crime, Drama \n", - "1065 Only the Brave Action, Biography, Drama \n", - "1066 Incredibles 2 Animation, Action, Adventure \n", - "1067 A Star Is Born Drama, Music, Romance \n", - "\n", - " Director Cast \\\n", - "0 James Gunn Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... \n", - "1 Ridley Scott Noomi Rapace, Logan Marshall-Green, Michael ... \n", - "2 M. Night Shyamalan James McAvoy, Anya Taylor-Joy, Haley Lu Richar... \n", - "3 Christophe Lourdelet Matthew McConaughey,Reese Witherspoon, Seth Ma... \n", - "4 David Ayer Will Smith, Jared Leto, Margot Robbie, Viola D... \n", - "... ... ... \n", - "1063 James Gunn Chris Pratt, Zoe Saldana, Dave Bautista, Vin D... \n", - "1064 Edgar Wright Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon... \n", - "1065 Joseph Kosinski Josh Brolin, Miles Teller, Jeff Bridges, Jenni... \n", - "1066 Brad Bird Craig T. Nelson, Holly Hunter, Sarah Vowell, H... \n", - "1067 Bradley Cooper Lady Gaga, Bradley Cooper, Sam Elliott, Greg G... \n", - "\n", - " Year Runtime Rating Revenue CountableRevenue \n", - "0 2014 121 8.1 333.13 333130000.0 \n", - "1 2012 124 7.0 126.46M 126460000.0 \n", - "2 2016 117 7.3 138.12M 138120000.0 \n", - "3 2016 108 7.2 270.32 270320000.0 \n", - "4 2016 123 6.2 325.02 325020000.0 \n", - "... ... ... ... ... ... \n", - "1063 2017 136 7.6 389.81 389810000.0 \n", - "1064 2017 113 7.6 107.83 107830000.0 \n", - "1065 2017 134 7.6 18.34 18340000.0 \n", - "1066 2018 118 7.6 608.58 608580000.0 \n", - "1067 2018 136 7.6 215.29 215290000.0 \n", - "\n", - "[1068 rows x 9 columns]" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Warmup 3b: Using the above function, create a new column called\n", - "# \"CountableRevenue\" with the revenue as a float.\n", - "\n", - "movies[\"CountableRevenue\"] = movies[\"Revenue\"].apply(format_revenue)\n", - "movies" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<style scoped>\n", - " .dataframe tbody tr th:only-of-type {\n", - " vertical-align: middle;\n", - " }\n", - "\n", - " .dataframe tbody tr th {\n", - " vertical-align: top;\n", - " }\n", - "\n", - " .dataframe thead th {\n", - " text-align: right;\n", - " }\n", - "</style>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>Title</th>\n", - " <th>Genre</th>\n", - " <th>Director</th>\n", - " <th>Cast</th>\n", - " <th>Year</th>\n", - " <th>Runtime</th>\n", - " <th>Rating</th>\n", - " <th>Revenue</th>\n", - " <th>CountableRevenue</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>50</th>\n", - " <td>Star Wars: Episode VII - The Force Awakens</td>\n", - " <td>Action,Adventure,Fantasy</td>\n", - " <td>J.J. Abrams</td>\n", - " <td>Daisy Ridley, John Boyega, Oscar Isaac, Domhna...</td>\n", - " <td>2015</td>\n", - " <td>136</td>\n", - " <td>8.1</td>\n", - " <td>936.63</td>\n", - " <td>936630000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1006</th>\n", - " <td>Avengers: Endgame</td>\n", - " <td>Action, Adventure, Drama</td>\n", - " <td>Anthony Russo</td>\n", - " <td>Joe Russo, Robert Downey Jr., Chris Evans, Mar...</td>\n", - " <td>2019</td>\n", - " <td>181</td>\n", - " <td>8.4</td>\n", - " <td>858.37</td>\n", - " <td>858370000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>87</th>\n", - " <td>Avatar</td>\n", - " <td>Action,Adventure,Fantasy</td>\n", - " <td>James Cameron</td>\n", - " <td>Sam Worthington, Zoe Saldana, Sigourney Weaver...</td>\n", - " <td>2009</td>\n", - " <td>162</td>\n", - " <td>7.8</td>\n", - " <td>760.51</td>\n", - " <td>760510000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1007</th>\n", - " <td>Avengers: Infinity War</td>\n", - " <td>Action, Adventure, Sci-Fi</td>\n", - " <td>Anthony Russo</td>\n", - " <td>Joe Russo, Robert Downey Jr., Chris Hemsworth,...</td>\n", - " <td>2018</td>\n", - " <td>149</td>\n", - " <td>8.4</td>\n", - " <td>678.82</td>\n", - " <td>678820000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>85</th>\n", - " <td>Jurassic World</td>\n", - " <td>Action,Adventure,Sci-Fi</td>\n", - " <td>Colin Trevorrow</td>\n", - " <td>Chris Pratt, Bryce Dallas Howard, Ty Simpkins,...</td>\n", - " <td>2015</td>\n", - " <td>124</td>\n", - " <td>7.0</td>\n", - " <td>652.18</td>\n", - " <td>652180000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>76</th>\n", - " <td>The Avengers</td>\n", - " <td>Action,Sci-Fi</td>\n", - " <td>Joss Whedon</td>\n", - " <td>Robert Downey Jr., Chris Evans, Scarlett Johan...</td>\n", - " <td>2012</td>\n", - " <td>143</td>\n", - " <td>8.1</td>\n", - " <td>623.28</td>\n", - " <td>623280000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>998</th>\n", - " <td>Hamilton</td>\n", - " <td>Biography, Drama, History</td>\n", - " <td>Thomas Kail</td>\n", - " <td>Lin-Manuel Miranda, Phillipa Soo, Leslie Odom ...</td>\n", - " <td>2020</td>\n", - " <td>160</td>\n", - " <td>8.6</td>\n", - " <td>612.82</td>\n", - " <td>612820000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1066</th>\n", - " <td>Incredibles 2</td>\n", - " <td>Animation, Action, Adventure</td>\n", - " <td>Brad Bird</td>\n", - " <td>Craig T. Nelson, Holly Hunter, Sarah Vowell, H...</td>\n", - " <td>2018</td>\n", - " <td>118</td>\n", - " <td>7.6</td>\n", - " <td>608.58</td>\n", - " <td>608580000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>54</th>\n", - " <td>The Dark Knight</td>\n", - " <td>Action,Crime,Drama</td>\n", - " <td>Christopher Nolan</td>\n", - " <td>Christian Bale, Heath Ledger, Aaron Eckhart,Mi...</td>\n", - " <td>2008</td>\n", - " <td>152</td>\n", - " <td>9.0</td>\n", - " <td>533.32</td>\n", - " <td>533320000.0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>12</th>\n", - " <td>Rogue One</td>\n", - " <td>Action,Adventure,Sci-Fi</td>\n", - " <td>Gareth Edwards</td>\n", - " <td>Felicity Jones, Diego Luna, Alan Tudyk, Donnie...</td>\n", - " <td>2016</td>\n", - " <td>133</td>\n", - " <td>7.9</td>\n", - " <td>532.17</td>\n", - " <td>532170000.0</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "</div>" - ], - "text/plain": [ - " Title \\\n", - "50 Star Wars: Episode VII - The Force Awakens \n", - "1006 Avengers: Endgame \n", - "87 Avatar \n", - "1007 Avengers: Infinity War \n", - "85 Jurassic World \n", - "76 The Avengers \n", - "998 Hamilton \n", - "1066 Incredibles 2 \n", - "54 The Dark Knight \n", - "12 Rogue One \n", - "\n", - " Genre Director \\\n", - "50 Action,Adventure,Fantasy J.J. Abrams \n", - "1006 Action, Adventure, Drama Anthony Russo \n", - "87 Action,Adventure,Fantasy James Cameron \n", - "1007 Action, Adventure, Sci-Fi Anthony Russo \n", - "85 Action,Adventure,Sci-Fi Colin Trevorrow \n", - "76 Action,Sci-Fi Joss Whedon \n", - "998 Biography, Drama, History Thomas Kail \n", - "1066 Animation, Action, Adventure Brad Bird \n", - "54 Action,Crime,Drama Christopher Nolan \n", - "12 Action,Adventure,Sci-Fi Gareth Edwards \n", - "\n", - " Cast Year Runtime \\\n", - "50 Daisy Ridley, John Boyega, Oscar Isaac, Domhna... 2015 136 \n", - "1006 Joe Russo, Robert Downey Jr., Chris Evans, Mar... 2019 181 \n", - "87 Sam Worthington, Zoe Saldana, Sigourney Weaver... 2009 162 \n", - "1007 Joe Russo, Robert Downey Jr., Chris Hemsworth,... 2018 149 \n", - "85 Chris Pratt, Bryce Dallas Howard, Ty Simpkins,... 2015 124 \n", - "76 Robert Downey Jr., Chris Evans, Scarlett Johan... 2012 143 \n", - "998 Lin-Manuel Miranda, Phillipa Soo, Leslie Odom ... 2020 160 \n", - "1066 Craig T. Nelson, Holly Hunter, Sarah Vowell, H... 2018 118 \n", - "54 Christian Bale, Heath Ledger, Aaron Eckhart,Mi... 2008 152 \n", - "12 Felicity Jones, Diego Luna, Alan Tudyk, Donnie... 2016 133 \n", - "\n", - " Rating Revenue CountableRevenue \n", - "50 8.1 936.63 936630000.0 \n", - "1006 8.4 858.37 858370000.0 \n", - "87 7.8 760.51 760510000.0 \n", - "1007 8.4 678.82 678820000.0 \n", - "85 7.0 652.18 652180000.0 \n", - "76 8.1 623.28 623280000.0 \n", - "998 8.6 612.82 612820000.0 \n", - "1066 7.6 608.58 608580000.0 \n", - "54 9.0 533.32 533320000.0 \n", - "12 7.9 532.17 532170000.0 " - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Warmup 4: What are the top 10 highest-revenue movies?\n", - "\n", - "movies.sort_values(by=\"CountableRevenue\", ascending=False).head(10)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Lecture 29: Web 1 - Getting Data\n", - "Learning Objectives\n", - "\n", - "- Make a request for data using `requests.get(URL)`\n", - "- Check the status of a request/response\n", - "- Extract the text of a response\n", - "- Create a json file from a response\n", - "- State and practice good etiquette when getting data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Make a request for data using `requests.get(URL)`\n", - "- URL: https://www.msyamkumar.com/hello.txt" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "200\n", - "Hello CS220 / CS319 students! Welcome to my website. Hope you are staying safe and healthy!\n", - "\n" - ] - } - ], - "source": [ - "url = \"https://www.msyamkumar.com/hello.txt\"\n", - "r = requests.get(url) # r is the response\n", - "print(r.status_code)\n", - "print(r.text)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### HTTP Status Codes you need to know\n", - "\n", - "- 200: success\n", - "- 404: not found\n", - "\n", - "Here is a list of all status codes, you do NOT need to memorize it\n", - "\n", - "https://en.wikipedia.org/wiki/List_of_HTTP_status_codes" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "404\n", - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", - "<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>meena/hello.txttttt</Key><RequestId>ZDQSDZQ6TJAKD3C5</RequestId><HostId>LxtxISgRp+SMDtG6Gez9rK+f2WZNyVyKQLU84qhxWPgYpF1A1clkGu3mfKiLQ4Lwe5lhoEXcxE0=</HostId></Error>\n" - ] - } - ], - "source": [ - "# Q: What if the web file does not exist?\n", - "typo_url = \"https://www.msyamkumar.com/hello.txttttt\"\n", - "r = requests.get(typo_url)\n", - "print(r.status_code)\n", - "print(r.text)\n", - "\n", - "# A: We get a 404 (client error)\n", - "# A: we get text, but the text is not from the client" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Check the status of a request/response\n" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "404\n" - ] - }, - { - "ename": "AssertionError", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m<ipython-input-15-820306369677>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtypo_url\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatus_code\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatus_code\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m200\u001b[0m \u001b[0;31m# change this\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mAssertionError\u001b[0m: " - ] - } - ], - "source": [ - "# We can check for a status_code error by using an assert\n", - "typo_url = \"https://www.msyamkumar.com/hello.txttttt\"\n", - "r = requests.get(typo_url)\n", - "print(r.status_code)\n", - "assert r.status_code == 200 # change this\n", - "print(r.text)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "ename": "HTTPError", - "evalue": "404 Client Error: Not Found for url: https://www.msyamkumar.com/hello.txttttt", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mHTTPError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m<ipython-input-16-d0650f24c881>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Instead of using an assert, we often use raise_for_status()\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtypo_url\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mraise_for_status\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m#similar to asserting r.status_code == 200\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/models.py\u001b[0m in \u001b[0;36mraise_for_status\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 941\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 942\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mhttp_error_msg\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 943\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mHTTPError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhttp_error_msg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresponse\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[0m\n\u001b[0m\u001b[1;32m 944\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 945\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mclose\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;31mHTTPError\u001b[0m: 404 Client Error: Not Found for url: https://www.msyamkumar.com/hello.txttttt" - ] - } - ], - "source": [ - "# Instead of using an assert, we often use raise_for_status()\n", - "r = requests.get(typo_url)\n", - "r.raise_for_status() #similar to asserting r.status_code == 200\n", - "r.text\n", - "\n", - "# Note the error you get.... We will use this in the next cell" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "oops!! 404 Client Error: Not Found for url: https://www.msyamkumar.com/hello.txttttt\n" - ] - } - ], - "source": [ - "# Let's try to catch that error\n", - "\n", - "try:\n", - " r = requests.get(typo_url)\n", - " r.raise_for_status() #similar to asserting r.status_code == 200\n", - " r.text\n", - "except requests.HTTPError as e:\n", - " print(\"oops!!\", e)\n", - " " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create a json file from a response\n", - "\n", - "- URL: https://www.msyamkumar.com/scores.json\n", - "- `json.load` (FILE_OBJECT)\n", - "- `json.loads` (STRING)" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{\n", - " \"alice\": 100,\n", - " \"bob\": 200,\n", - " \"cindy\": 300\n", - "}\n", - "\n", - "<class 'dict'> {'alice': 100, 'bob': 200, 'cindy': 300}\n" - ] - } - ], - "source": [ - "# GETting a JSON file, the long way\n", - "url = \"https://www.msyamkumar.com/scores.json\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "urltext = r.text\n", - "print(urltext)\n", - "d = json.loads(urltext)\n", - "print(type(d), d)" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "<class 'dict'> {'alice': 100, 'bob': 200, 'cindy': 300}\n" - ] - } - ], - "source": [ - "# GETting a JSON file, the shortcut way\n", - "url = \"https://www.msyamkumar.com/scores.json\"\n", - "#Shortcut to bypass using json.loads()\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "d2 = r.json()\n", - "print(type(d2), d2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Good GET Etiquette\n", - "\n", - "Don't make a lot of requests to the same server all at once.\n", - " - Requests use up the server's time\n", - " - Major websites will often ban users who make too many requests\n", - " - You can break a server....similar to DDoS attacks (DON'T DO THIS)\n", - " \n", - "In CS220 we will usually give you a link to a copied file to avoid overloading the site.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## DEMO: Course Enrollment" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Explore the API!\n", - "\n", - "https://coletnelson.us/cs220-api/classes\n", - "\n", - "https://coletnelson.us/cs220-api/classes_as_txt\n", - "\n", - "https://coletnelson.us/cs220-api/classes/MATH_221\n", - "\n", - "https://coletnelson.us/cs220-api/classes/COMPSCI_200\n", - "\n", - "... etc\n", - "\n", - "https://coletnelson.us/cs220-api/all_data" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Get the list of classes." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### When the data is `json`" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "<class 'list'>\n", - "['PSYCH_202', 'COMPSCI_537', 'COMPSCI_300', 'CHEM_104', 'COMPSCI_200', 'MATH_114', 'PSYCH_456', 'COMPSCI_252', 'COMPSCI_400', 'MATH_221', 'BIOLOGY_101', 'COMPSCI_354', 'CHEM_103', 'COMPSCI_639', 'PSYCH_401', 'COMPSCI_240', 'STATS_302']\n" - ] - } - ], - "source": [ - "url = \"https://coletnelson.us/cs220-api/classes\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "classes_list = r.json() # what goes here? \n", - "print(type(classes_list))\n", - "print(classes_list)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### When the data is `text`" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "url = \"https://coletnelson.us/cs220-api/classes_as_txt\"\n", - "r = requests.get(url)\n", - "r.raise_for_status()\n", - "classes_txt = None # what goes here? \n", - "print(type(classes_txt))\n", - "print(classes_txt)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Get data for a specific class" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [], - "source": [ - "# Work-around: Read the data in as a JSON file\n", - "# use this function\n", - "\n", - "\n", - "# Deserialize\n", - "def read_json(path):\n", - " with open(path, encoding=\"utf-8\") as f: # f is a varaible \n", - " return json.load(f) # f represents a reference the JSON file\n", - " \n", - " \n", - "# Serialize\n", - "def write_json(path, data):\n", - " with open(path, 'w', encoding=\"utf-8\") as f:\n", - " json.dump(data, f, indent=2)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "8" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#read this data from the json file:\n", - "cs200_data = read_json(\"cs200_data.json\")\n", - "len(cs200_data)" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "dict_keys(['credits', 'description', 'keywords', 'name', 'number', 'requisites', 'sections', 'subject'])" - ] - }, - "execution_count": 38, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "cs200_data.keys()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Get the number of credits the course is worth\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Get the list of keywords for the course\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Get the official course name\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Get the number of sections offered.\n" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "17\n" - ] - } - ], - "source": [ - "print(len(all_class_data))" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [], - "source": [ - "# write it out to a json file locally\n", - "write_json(\"all_class_data.json\", all_class_data)" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "17" - ] - }, - "execution_count": 40, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# read in the all_class data as a json file\n", - "all_class_data = read_json(\"all_class_data.json\")\n", - "len(all_class_data)" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "list" - ] - }, - "execution_count": 43, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "type(all_class_data)" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'credits': 3,\n", - " 'description': 'Behavior, including its development, motivation, frustrations, emotion, intelligence, learning, forgetting, personality, language, thinking, and social behavior.',\n", - " 'keywords': ['psychology', 'behavior', 'emotion', 'intelligence', 'brain'],\n", - " 'name': 'Introduction to Psychology',\n", - " 'number': 'PSYCH_202',\n", - " 'requisites': [],\n", - " 'sections': [{'instructor': 'Jeff Henriques',\n", - " 'location': '105 Brogden Psychology Building',\n", - " 'subsections': [],\n", - " 'time': {'thursday': '9:30am - 10:45am', 'tuesday': '9:30am - 10:45am'},\n", - " 'number': 'LEC_001'},\n", - " {'instructor': 'Jeff Henriques',\n", - " 'location': '105 Brogden Psychology Building',\n", - " 'subsections': [],\n", - " 'time': {'thursday': '11:00am - 12:15pm', 'tuesday': '11:00am - 12:15pm'},\n", - " 'number': 'LEC_002'},\n", - " {'instructor': 'C. Shawn Green',\n", - " 'location': '105 Brogden Psychology Building',\n", - " 'subsections': [],\n", - " 'time': {'monday': '8:00am - 9:15am', 'wednesday': '8:00am - 9:15am'},\n", - " 'number': 'LEC_003'},\n", - " {'instructor': 'Patti Coffey',\n", - " 'location': '105 Brogden Psychology Building',\n", - " 'subsections': [],\n", - " 'time': {'thursday': '1:00pm - 2:15pm', 'tuesday': '1:00pm - 2:15pm'},\n", - " 'number': 'LEC_004'},\n", - " {'instructor': 'Sarah Gavac',\n", - " 'location': '105 Brogden Psychology Building',\n", - " 'subsections': [],\n", - " 'time': {'thursday': '2:30pm - 3:45pm', 'tuesday': '2:30pm - 3:45pm'},\n", - " 'number': 'LEC_005'},\n", - " {'instructor': 'Patti Coffey',\n", - " 'location': '101 Brogden Psychology Building',\n", - " 'subsections': [],\n", - " 'time': {'thursday': '2:30pm - 3:45pm', 'tuesday': '2:30pm - 3:45pm'},\n", - " 'number': 'LEC_006'},\n", - " {'instructor': 'Baoyu Wang',\n", - " 'location': '105 Brogden Psychology Building',\n", - " 'subsections': [],\n", - " 'time': {'monday': '4:30pm - 5:15pm', 'wednesday': '4:30pm - 5:15pm'},\n", - " 'number': 'LEC_009'}],\n", - " 'subject': 'Psychology'}" - ] - }, - "execution_count": 44, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# print out the first dictionary in this list\n", - "all_class_data[0]" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3 PSYCH_202 Introduction to Psychology\n", - "4 COMPSCI_537 Introduction to Operating Systems\n", - "3 COMPSCI_300 Programming 2\n", - "5 CHEM_104 General Chemistry II\n", - "3 COMPSCI_200 Programming 1\n", - "5 MATH_114 Algebra and Trigonometry\n", - "4 PSYCH_456 Introductory Social Psychology\n", - "2 COMPSCI_252 Introduction to Computer Engineering\n", - "3 COMPSCI_400 Programming 3\n", - "5 MATH_221 Calculus and Analytical Geometry 1\n", - "3 BIOLOGY_101 Animal Biology\n", - "3 COMPSCI_354 Machine Organization and Programming\n", - "4 CHEM_103 General Chemistry I\n", - "3 COMPSCI_639 Building User Interfaces\n", - "3 PSYCH_401 Psychology, Law, and Social Policy\n", - "3 COMPSCI_240 Introduction To Discrete Mathematics\n", - "3 STATS_302 Accelerated Introduction to Statistical Methods\n" - ] - } - ], - "source": [ - "# Print the number of credits, course number, and name for each class.\n", - "for item in all_class_data:\n", - " print(item['credits'], item['number'], item['name'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What is the average number of credits per course?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What are the unique subjects?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Besides PYSCH 202, what are the course numbers of the courses\n", - "# with the most sections offered (not including subsections)?\n", - "high_courses = []\n", - "high_sections = 0\n", - "for spec_class in all_class_data:\n", - " pass\n", - "high_courses" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Can we make a Pandas dataframe? Yes!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "all_course_frame = DataFrame(all_class_data)\n", - "all_course_frame" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### We may want to do some \"plumbing\" with our data." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Remove the 'sections' and 'requisites' column.\n", - "new_course_frame = all_course_frame.loc[:, \"credits\":\"number\"]\n", - "new_course_frame[\"subject\"] = all_course_frame.loc[:, \"subject\"]\n", - "new_course_frame" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Turn 'keywords' into a series of Strings and remove the '[', ']', '''\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].astype('string')\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].str.replace(\"[\", \"\", regex=False)\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].str.replace(\"]\", \"\", regex=False)\n", - "new_course_frame[\"keywords\"] = new_course_frame[\"keywords\"].str.replace(\"'\", \"\", regex=False)\n", - "new_course_frame" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Pandas Operations" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What is the most number of credits a course offers?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What is the least number of credits a course offers?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What is the info for that course?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What courses contain the keyword \"programming\"?\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# What course has the most lengthy description?\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Write it out to a CSV file on your drive\n", - "You now have your own copy!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Write it all out to a single CSV file\n", - "new_course_frame.to_csv(\"my_course_data.csv\", index=False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Other Cool APIs" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- City of Madison Transit: http://transitdata.cityofmadison.com/\n", - "- Reddit: https://reddit.com/r/UWMadison.json\n", - "- Lord of the Rings: https://the-one-api.dev/\n", - "- Pokemon: https://pokeapi.co/\n", - "\n", - "Remember: Be judicious when making requests; don't overwhelm the server! :)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Next Time\n", - "What other documents can we get via the Web? HTML is very popular! We'll explore this." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.1" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/f22/andy_lec_notes/lec29_Nov16_Web1/all_class_data.json b/f22/andy_lec_notes/lec29_Nov16_Web1/all_class_data.json deleted file mode 100644 index c7bc467bffb6cfccd2185feebee5eab835756585..0000000000000000000000000000000000000000 --- a/f22/andy_lec_notes/lec29_Nov16_Web1/all_class_data.json +++ /dev/null @@ -1,1470 +0,0 @@ -[ - { - "credits": 3, - "description": "Behavior, including its development, motivation, frustrations, emotion, intelligence, learning, forgetting, personality, language, thinking, and social behavior.", - "keywords": [ - "psychology", - "behavior", - "emotion", - "intelligence", - "brain" - ], - "name": "Introduction to Psychology", - "number": "PSYCH_202", - "requisites": [], - "sections": [ - { - "instructor": "Jeff Henriques", - "location": "105 Brogden Psychology Building", - "subsections": [], - "time": { - "thursday": "9:30am - 10:45am", - "tuesday": "9:30am - 10:45am" - }, - "number": "LEC_001" - }, - { - "instructor": "Jeff Henriques", - "location": "105 Brogden Psychology Building", - "subsections": [], - "time": { - "thursday": "11:00am - 12:15pm", - "tuesday": "11:00am - 12:15pm" - }, - "number": "LEC_002" - }, - { - "instructor": "C. Shawn Green", - "location": "105 Brogden Psychology Building", - "subsections": [], - "time": { - "monday": "8:00am - 9:15am", - "wednesday": "8:00am - 9:15am" - }, - "number": "LEC_003" - }, - { - "instructor": "Patti Coffey", - "location": "105 Brogden Psychology Building", - "subsections": [], - "time": { - "thursday": "1:00pm - 2:15pm", - "tuesday": "1:00pm - 2:15pm" - }, - "number": "LEC_004" - }, - { - "instructor": "Sarah Gavac", - "location": "105 Brogden Psychology Building", - "subsections": [], - "time": { - "thursday": "2:30pm - 3:45pm", - "tuesday": "2:30pm - 3:45pm" - }, - "number": "LEC_005" - }, - { - "instructor": "Patti Coffey", - "location": "101 Brogden Psychology Building", - "subsections": [], - "time": { - "thursday": "2:30pm - 3:45pm", - "tuesday": "2:30pm - 3:45pm" - }, - "number": "LEC_006" - }, - { - "instructor": "Baoyu Wang", - "location": "105 Brogden Psychology Building", - "subsections": [], - "time": { - "monday": "4:30pm - 5:15pm", - "wednesday": "4:30pm - 5:15pm" - }, - "number": "LEC_009" - } - ], - "subject": "Psychology" - }, - { - "credits": 4, - "description": "Input-output hardware, interrupt handling, properties of magnetic tapes, discs and drums, associative memories and virtual address translation techniques. Batch processing, time sharing and real-time systems, scheduling resource allocation, modular software systems, performance measurement and system evaluation.", - "keywords": [ - "computer", - "science", - "operating", - "system", - "systems" - ], - "name": "Introduction to Operating Systems", - "number": "COMPSCI_537", - "requisites": [ - [ - "COMPSCI_354", - "COMPSCI_400" - ] - ], - "sections": [ - { - "instructor": "Andrea Arpaci-Dusseau", - "location": "1125 DeLuca Biochemistry Building", - "subsections": [ - { - "location": "2317 Engineering Hall", - "time": { - "wednesday": "11:00am - 11:50am" - }, - "number": "DIS_301" - }, - { - "location": "1325 Computer Sciences and Statistics", - "time": { - "wednesday": "12:05pm - 12:55pm" - }, - "number": "DIS_302" - }, - { - "location": "1325 Computer Sciences and Statistics", - "time": { - "wednesday": "1:20pm - 2:10pm" - }, - "number": "DIS_303" - }, - { - "location": "2255 Engineering Hall", - "time": { - "wednesday": "3:30pm - 4:20pm" - }, - "number": "DIS_304" - }, - { - "location": "1325 Computer Sciences and Statistics", - "time": { - "wednesday": "4:15pm - 5:25pm" - }, - "number": "DIS_305" - } - ], - "time": { - "thursday": "11:00am - 12:15pm", - "tuesday": "11:00am - 12:15pm" - }, - "number": "LEC_001" - } - ], - "subject": "Computer Science" - }, - { - "credits": 3, - "description": "Introduces students to Object-Oriented Programming using classes and objects to solve more complex problems. Introduces array-based and linked data structures: including lists, stacks, and queues. Programming assignments require writing and developing multi-class (file) programs using interfaces, generics, and exception handling to solve challenging real world problems. Topics reviewed include reading/writing data and objects from/to files and exception handling, and command line arguments. Topics introduced: object-oriented design; class vs. object; create and define interfaces and iterators; searching and sorting; abstract data types (List,Stack,Queue,PriorityQueue(Heap),Binary Search Tree); generic interfaces (parametric polymorphism); how to design and write test methods and classes; array based vs. linked node implementations; introduction to complexity analysis; recursion.", - "keywords": [ - "computer", - "science", - "programming", - "java" - ], - "name": "Programming 2", - "number": "COMPSCI_300", - "requisites": [ - [ - "COMPSCI_200" - ] - ], - "sections": [ - { - "instructor": "Gary Dahl", - "location": "AB20 Weeks Hall for Geological Sciences", - "subsections": [], - "time": { - "thursday": "2:30pm - 3:45pm", - "tuesday": "2:30pm - 3:45pm" - }, - "number": "LEC_001" - }, - { - "instructor": "Gary Dahl", - "location": "132 Noland Hall", - "subsections": [], - "time": { - "thursday": "1:00pm - 2:15pm", - "tuesday": "1:00pm - 2:15pm" - }, - "number": "LEC_002" - }, - { - "instructor": "Mouna Ayari Ben Hadj Kacem", - "location": "AB20 Weeks Hall for Geological Sciences", - "subsections": [], - "time": { - "friday": "11:00am - 11:50pm", - "monday": "11:00am - 11:50pm", - "wednesday": "11:00am - 11:50pm" - }, - "number": "LEC_003" - }, - { - "instructor": "Mouna Ayari Ben Hadj Kacem", - "location": "1310 Sterling Hall", - "subsections": [], - "time": { - "friday": "2:25pm - 3:15pm", - "monday": "2:25pm - 3:15pm", - "wednesday": "2:25pm - 3:15pm" - }, - "number": "LEC_004" - } - ], - "subject": "Computer Science" - }, - { - "credits": 5, - "description": "Principles and application of chemical equilibrium, coordination chemistry, oxidation-reduction and electrochemistry, kinetics, nuclear chemistry, introduction to organic chemistry. Lecture, lab, and discussion.", - "keywords": [ - "chemistry" - ], - "name": "General Chemistry II", - "number": "CHEM_104", - "requisites": [ - [ - "MATH_114" - ], - [ - "CHEM_103" - ] - ], - "sections": [ - { - "instructor": "Linda Zelewski", - "location": "B10 Ingraham Hall", - "subsections": [ - { - "location": "123 Van Hise Hall", - "time": { - "monday": "2:25pm - 5:25pm", - "thursday": "11:00am - 11:50am", - "tuesday": "11:00am - 11:50am" - }, - "number": "DIS_401" - }, - { - "location": "123 Van Hise Hall", - "time": { - "monday": "2:25pm - 5:25pm", - "thursday": "12:05pm - 12:55pm", - "tuesday": "12:05pm - 12:55pm" - }, - "number": "DIS_402" - }, - { - "location": "B387 Chemistry Building", - "time": { - "monday": "2:25pm - 5:25pm", - "thursday": "11:00am - 11:50am", - "tuesday": "11:00am - 11:50am" - }, - "number": "DIS_403" - }, - { - "location": "B387 Chemistry Building", - "time": { - "monday": "2:25pm - 5:25pm", - "thursday": "12:05pm - 12:55pm", - "tuesday": "12:05pm - 12:55pm" - }, - "number": "DIS_404" - } - ], - "time": { - "thursday": "9:30am - 10:45am", - "tuesday": "9:30am - 10:45am" - }, - "number": "LEC_001" - }, - { - "instructor": "Lea Gustin", - "location": "204 Educational Sciences", - "subsections": [ - { - "location": "2377 Chemistry Building", - "time": { - "monday": "9:55am - 10:45am", - "tuesday": "5:40pm - 8:40pm", - "wednesday": "9:55am - 10:45am" - }, - "number": "DIS_421" - }, - { - "location": "2377 Chemistry Building", - "time": { - "monday": "11:00am - 11:50am", - "tuesday": "5:40pm - 8:40pm", - "wednesday": "11:00am - 11:50am" - }, - "number": "DIS_422" - }, - { - "location": "2381 Chemistry Building", - "time": { - "monday": "11:00am - 11:50am", - "tuesday": "5:40pm - 8:40pm", - "wednesday": "11:00am - 11:50am" - }, - "number": "DIS_423" - }, - { - "location": "2377 Chemistry Building", - "time": { - "monday": "12:05pm - 12:55pm", - "tuesday": "5:40pm - 8:40pm", - "wednesday": "12:05pm - 12:55pm" - }, - "number": "DIS_424" - } - ], - "time": { - "thursday": "1:00pm - 2:15pm", - "tuesday": "1:00pm - 2:15pm" - }, - "number": "LEC_002" - } - ], - "subject": "Chemistry" - }, - { - "credits": 3, - "description": "Learn the process of incrementally developing small (200-500 lines) programs along with the fundamental Computer Science topics. These topics include: problem abstraction and decomposition, the edit-compile-run cycle, using variables of primitive and more complex data types, conditional and loop-based flow control, basic testing and debugging techniques, how to define and call functions (methods), and IO processing techniques. Also teaches and reinforces good programming practices including the use of a consistent style, and meaningful documentation. Intended for students who have no prior programming experience.", - "keywords": [ - "computer", - "science", - "programming", - "java" - ], - "name": "Programming 1", - "number": "COMPSCI_200", - "requisites": [], - "sections": [ - { - "instructor": "Jim Williams", - "location": "132 Noland Hall", - "subsections": [ - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "wednesday": "9:30am - 10:45am" - }, - "number": "LAB_311" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "wednesday": "11:00am - 12:15pm" - }, - "number": "LAB_312" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "wednesday": "2:30pm - 3:45pm" - }, - "number": "LAB_314" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "wednesday": "4:00pm - 5:15pm" - }, - "number": "LAB_315" - } - ], - "time": { - "thursday": "8:00am - 9:15am", - "tuesday": "8:00am - 9:15am" - }, - "number": "LEC_001" - }, - { - "instructor": "Jim Williams", - "location": "132 Noland Hall", - "subsections": [ - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "wednesday": "9:30am - 10:45am" - }, - "number": "LAB_321" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "wednesday": "1:00pm - 2:15pm" - }, - "number": "LAB_323" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "wednesday": "2:30pm - 3:45pm" - }, - "number": "LAB_324" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "wednesday": "4:00pm - 5:15pm" - }, - "number": "LAB_325" - } - ], - "time": { - "thursday": "11:00am - 12:15pm", - "tuesday": "11:00am - 12:15pm" - }, - "number": "LEC_002" - }, - { - "instructor": "Marc Renault", - "location": "113 Brogden Psychology Building", - "subsections": [ - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "tuesday": "9:30am - 10:45am" - }, - "number": "LAB_331" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "tuesday": "11:00am - 12:15pm" - }, - "number": "LAB_332" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "tuesday": "1:00pm - 2:15pm" - }, - "number": "LAB_333" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "tuesday": "2:30pm - 3:45pm" - }, - "number": "LAB_334" - } - ], - "time": { - "friday": "1:20pm - 2:10pm", - "monday": "1:20pm - 2:10pm", - "wednesday": "1:20pm - 2:10pm" - }, - "number": "LEC_003" - }, - { - "instructor": "Marc Renault", - "location": "113 Brogden Psychology Building", - "subsections": [ - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "tuesday": "9:30am - 10:45am" - }, - "number": "LAB_341" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "tuesday": "11:00am - 12:15pm" - }, - "number": "LAB_342" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "tuesday": "1:00pm - 2:15pm" - }, - "number": "LAB_343" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "tuesday": "2:30pm - 3:45pm" - }, - "number": "LAB_344" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "tuesday": "4:00pm - 5:15pm" - }, - "number": "LAB_345" - } - ], - "time": { - "friday": "3:30pm - 4:20pm", - "monday": "3:30pm - 4:20pm", - "wednesday": "3:30pm - 4:20pm" - }, - "number": "LEC_004" - } - ], - "subject": "Computer Science" - }, - { - "credits": 5, - "description": "The two semester sequence MATH_112-MATH_113 covers similar material as MATH_114, but in a slower pace.", - "keywords": [ - "math", - "mathematics", - "algebra", - "trigonometry" - ], - "name": "Algebra and Trigonometry", - "number": "MATH_114", - "requisites": [], - "sections": [ - { - "instructor": "Sharad Chandarana", - "location": "B130 Van Vleck Hall", - "subsections": [ - { - "location": "B113 Van Vleck Hall", - "time": { - "monday": "7:45am - 8:35am", - "wednesday": "7:45am - 8:35am" - }, - "number": "DIS_301" - }, - { - "location": "B113 Van Vleck Hall", - "time": { - "monday": "8:50am - 9:40am", - "wednesday": "8:50am - 9:40am" - }, - "number": "DIS_303" - }, - { - "location": "B219 Van Vleck Hall", - "time": { - "monday": "8:50am - 9:40am", - "wednesday": "8:50am - 9:40am" - }, - "number": "DIS_304" - }, - { - "location": "B113 Van Vleck Hall", - "time": { - "monday": "9:55am - 10:45am", - "wednesday": "9:55am - 10:45am" - }, - "number": "DIS_305" - }, - { - "location": "B219 Van Vleck Hall", - "time": { - "monday": "9:55am - 10:45am", - "wednesday": "9:55am - 10:45am" - }, - "number": "DIS_306" - }, - { - "location": "B341 Van Vleck Hall", - "time": { - "monday": "1:20pm - 2:10pm", - "wednesday": "1:20pm - 2:10pm" - }, - "number": "DIS_307" - }, - { - "location": "B317 Van Vleck Hall", - "time": { - "monday": "1:20pm - 2:10pm", - "wednesday": "1:20pm - 2:10pm" - }, - "number": "DIS_308" - }, - { - "location": "B341 Van Vleck Hall", - "time": { - "monday": "2:25pm - 3:15pm", - "wednesday": "2:25pm - 3:15pm" - }, - "number": "DIS_309" - }, - { - "location": "B329 Van Vleck Hall", - "time": { - "monday": "2:25pm - 3:15pm", - "wednesday": "2:25pm - 3:15pm" - }, - "number": "DIS_310" - }, - { - "location": "B317 Van Vleck Hall", - "time": { - "monday": "7:45am - 8:35am", - "wednesday": "7:45am - 8:35am" - }, - "number": "DIS_311" - } - ], - "time": { - "thursday": "2:30pm - 3:45pm", - "tuesday": "2:30pm - 3:45pm" - }, - "number": "LEC_001" - }, - { - "instructor": "Sharad Chandarana", - "location": "19 Ingraham Hall", - "subsections": [ - { - "location": "591 Van Hise Hall", - "time": { - "thursday": "8:50am - 9:40am", - "tuesday": "8:50am - 9:40am" - }, - "number": "DIS_321" - }, - { - "location": "B219 Van Vleck Hall", - "time": { - "thursday": "9:55am - 10:45am", - "tuesday": "9:55am - 10:45am" - }, - "number": "DIS_322" - }, - { - "location": "4020 Vilas Hall", - "time": { - "thursday": "11:00am - 11:50am", - "tuesday": "11:00am - 11:50am" - }, - "number": "DIS_323" - }, - { - "location": "599 Van Hise Hall", - "time": { - "thursday": "11:00am - 11:50am", - "tuesday": "11:00am - 11:50am" - }, - "number": "DIS_324" - }, - { - "location": "B341 Van Vleck Hall", - "time": { - "thursday": "1:20pm - 2:10pm", - "tuesday": "1:20pm - 2:10pm" - }, - "number": "DIS_325" - }, - { - "location": "223 Van Hise Hall", - "time": { - "thursday": "1:20pm - 2:10pm", - "tuesday": "1:20pm - 2:10pm" - }, - "number": "DIS_326" - }, - { - "location": "223 Van Hise Hall", - "time": { - "thursday": "2:25pm - 3:15pm", - "tuesday": "2:25pm - 3:15pm" - }, - "number": "DIS_328" - }, - { - "location": "B219 Van Vleck Hall", - "time": { - "thursday": "3:30pm - 4:20pm", - "tuesday": "3:30pm - 4:20pm" - }, - "number": "DIS_329" - }, - { - "location": "B341 Van Vleck Hall", - "time": { - "thursday": "3:30pm - 4:20pm", - "tuesday": "3:30pm - 4:20pm" - }, - "number": "DIS_330" - } - ], - "time": { - "friday": "8:50am - 9:40am", - "monday": "8:50am - 9:40am", - "wednesday": "8:50am - 9:40am" - }, - "number": "LEC_002" - } - ], - "subject": "Mathematics" - }, - { - "credits": 4, - "description": "The systematic study of the individual in a social context, including social interaction, motivation, attitudes, conformity, communication, leadership, personal relationships, and behavior in small groups.", - "keywords": [ - "psychology", - "science", - "social", - "interaction", - "behavior" - ], - "name": "Introductory Social Psychology", - "number": "PSYCH_456", - "requisites": [ - [ - "PSYCH_202" - ] - ], - "sections": [ - { - "instructor": "Abigail Letak", - "location": "6104 Sewell Social Sciences", - "subsections": [ - { - "location": "6121 Sewell Social Sciences", - "time": { - "tuesday": "8:50am - 9:40am" - }, - "number": "DIS_301" - }, - { - "location": "6121 Sewell Social Sciences", - "time": { - "tuesday": "9:55am - 10:45am" - }, - "number": "DIS_302" - }, - { - "location": "6121 Sewell Social Sciences", - "time": { - "tuesday": "11:00am - 11:50am" - }, - "number": "DIS_303" - }, - { - "location": "6121 Sewell Social Sciences", - "time": { - "tuesday": "1:20pm - 2:10pm" - }, - "number": "DIS_304" - }, - { - "location": "6121 Sewell Social Sciences", - "time": { - "tuesday": "2:25pm - 3:15pm" - }, - "number": "DIS_305" - } - ], - "time": { - "friday": "11:00am - 11:50am", - "monday": "11:00am - 11:50am", - "wednesday": "11:00am - 11:50am" - }, - "number": "LEC_001" - } - ], - "subject": "Psychology" - }, - { - "credits": 2, - "description": "Logic components built with transistors, rudimentary Boolean algebra, basic combinational logic design, basic synchronous sequential logic design, basic computer organization and design, introductory machine- and assembly-language programming.", - "keywords": [ - "computer", - "science", - "engineering", - "programming" - ], - "name": "Introduction to Computer Engineering", - "number": "COMPSCI_252", - "requisites": [], - "sections": [ - { - "instructor": "Joseph Krachey", - "location": "1610 Engineering Hall", - "subsections": [], - "time": { - "friday": "2:25pm - 3:15pm", - "monday": "2:25pm - 3:15pm", - "wednesday": "2:25pm - 3:15pm" - }, - "number": "LEC_001" - }, - { - "instructor": "Adil Ibrahim", - "location": "113 Brogden Psychology Building", - "subsections": [], - "time": { - "friday": "8:50am - 9:40am", - "monday": "8:50am - 9:40am", - "wednesday": "8:50am - 9:40am" - }, - "number": "LEC_002" - }, - { - "instructor": "Adil Ibrahim", - "location": "113 Brogden Psychology Building", - "subsections": [], - "time": { - "friday": "12:05pm - 12:55pm", - "monday": "12:05pm - 12:55pm", - "wednesday": "12:05pm - 12:55pm" - }, - "number": "LEC_005" - } - ], - "subject": "Computer Science" - }, - { - "credits": 3, - "description": "The third course in our programming fundamentals sequence. It presumes that students understand and use functional and object-oriented design and abstract data types as needed. This course introduces balanced search trees, graphs, graph traversal algorithms, hash tables and sets, and complexity analysis and about classes of problems that require each data type. Students are required to design and implement using high quality professional code, a medium sized program, that demonstrates knowledge and use of latest language features, tools, and conventions. Additional topics introduced will include as needed for projects: inheritance and polymorphism; anonymous inner classes, lambda functions, performance analysis to discover and optimize critical code blocks. Students learn about industry standards for code development. Students will design and implement a medium size project with a more advanced user-interface design, such as a web or mobile application with a GUI and event- driven implementation; use of version-control software.", - "keywords": [ - "computer", - "science", - "programming", - "java" - ], - "name": "Programming 3", - "number": "COMPSCI_400", - "requisites": [ - [ - "COMPSCI_300" - ] - ], - "sections": [ - { - "instructor": "Gary Dahl", - "location": "AB20 Weeks Hall for Geological Sciences", - "subsections": [], - "time": { - "thursday": "2:30pm - 3:45pm", - "tuesday": "2:30pm - 3:45pm" - }, - "number": "LEC_001" - }, - { - "instructor": "Gary Dahl", - "location": "132 Noland Hall", - "subsections": [], - "time": { - "thursday": "1:00pm - 2:15pm", - "tuesday": "1:00pm - 2:15pm" - }, - "number": "LEC_002" - }, - { - "instructor": "Mouna Ayari Ben Hadj Kacem", - "location": "AB20 Weeks Hall for Geological Sciences", - "subsections": [], - "time": { - "friday": "11:00am - 11:50pm", - "monday": "11:00am - 11:50pm", - "wednesday": "11:00am - 11:50pm" - }, - "number": "LEC_003" - }, - { - "instructor": "Mouna Ayari Ben Hadj Kacem", - "location": "1310 Sterling Hall", - "subsections": [], - "time": { - "friday": "2:25pm - 3:15pm", - "monday": "2:25pm - 3:15pm", - "wednesday": "2:25pm - 3:15pm" - }, - "number": "LEC_004" - } - ], - "subject": "Computer Science" - }, - { - "credits": 5, - "description": "Introduction to differential and integral calculus and plane analytic geometry; applications; transcendental functions.", - "keywords": [ - "math", - "mathematics", - "calculus", - "analytical", - "geometry", - "differential", - "integral" - ], - "name": "Calculus and Analytical Geometry 1", - "number": "MATH_221", - "requisites": [ - [ - "MATH_114" - ] - ], - "sections": [ - { - "instructor": "Laurentiu Maxim", - "location": "6210 Sewell Social Sciences", - "subsections": [ - { - "location": "B231 Van Vleck Hall", - "time": { - "monday": "7:45am - 8:35am", - "wednesday": "7:45am - 8:35am" - }, - "number": "DIS_301" - }, - { - "location": "B215 Van Vleck Hall", - "time": { - "monday": "7:45am - 8:35am", - "wednesday": "7:45am - 8:35am" - }, - "number": "DIS_302" - }, - { - "location": "B309 Van Vleck Hall", - "time": { - "monday": "3:30pm - 4:20pm", - "wednesday": "3:30pm - 4:20pm" - }, - "number": "DIS_303" - }, - { - "location": "B211 Van Vleck Hall", - "time": { - "monday": "3:30pm - 4:20pm", - "wednesday": "3:30pm - 4:20pm" - }, - "number": "DIS_304" - }, - { - "location": "B129 Van Vleck Hall", - "time": { - "monday": "11:00am - 11:50am", - "wednesday": "11:00am - 11:50am" - }, - "number": "DIS_305" - }, - { - "location": "B131 Van Vleck Hall", - "time": { - "monday": "11:00am - 11:50am", - "wednesday": "11:00am - 11:50am" - }, - "number": "DIS_306" - }, - { - "location": "B231 Van Vleck Hall", - "time": { - "monday": "12:05pm - 12:55pm", - "wednesday": "12:05pm - 12:55pm" - }, - "number": "DIS_307" - }, - { - "location": "B215 Van Vleck Hall", - "time": { - "monday": "12:05pm - 12:55pm", - "wednesday": "12:05pm - 12:55pm" - }, - "number": "DIS_308" - }, - { - "location": "B313 Van Vleck Hall", - "time": { - "monday": "1:20pm - 2:10pm", - "wednesday": "1:20pm - 2:10pm" - }, - "number": "DIS_309" - }, - { - "location": "B309 Van Vleck Hall", - "time": { - "monday": "1:20pm - 2:10pm", - "wednesday": "1:20pm - 2:10pm" - }, - "number": "DIS_310" - }, - { - "location": "B305 Van Vleck Hall", - "time": { - "monday": "2:25pm - 3:15pm", - "wednesday": "2:25pm - 3:15pm" - }, - "number": "DIS_311" - }, - { - "location": "B105 Van Vleck Hall", - "time": { - "monday": "2:25pm - 3:15pm", - "wednesday": "2:25pm - 3:15pm" - }, - "number": "DIS_312" - }, - { - "location": "B321 Van Vleck Hall", - "time": { - "friday": "9:55am - 10:45am", - "monday": "9:55am - 10:45am", - "wednesday": "9:55am - 10:45am" - }, - "number": "DIS_313" - } - ], - "time": { - "thursday": "1:00pm - 2:15pm", - "tuesday": "1:00pm - 2:15pm" - }, - "number": "LEC_001" - } - ], - "subject": "Mathematics" - }, - { - "credits": 3, - "description": "General biological principles. Topics include: evolution, ecology, animal behavior, cell structure and function, genetics and molecular genetics and the physiology of a variety of organ systems emphasizing function in humans.", - "keywords": [ - "biology", - "science", - "animal", - "evolution", - "genetics", - "ecology" - ], - "name": "Animal Biology", - "number": "BIOLOGY_101", - "requisites": [], - "sections": [ - { - "instructor": "Sharon Thoma", - "location": "272 Bascom Hall", - "subsections": [], - "time": { - "friday": "11:00am - 11:50am", - "monday": "11:00am - 11:50am", - "wednesday": "11:00am - 11:50am" - }, - "number": "LEC_001" - }, - { - "instructor": "Sharon Thoma", - "location": "272 Bascom Hall", - "subsections": [], - "time": { - "friday": "12:05pm - 12:55pm", - "monday": "12:05pm - 12:55pm", - "wednesday": "12:05pm - 12:55pm" - }, - "number": "LEC_002" - } - ], - "subject": "Biology" - }, - { - "credits": 3, - "description": "An introduction to fundamental structures of computer systems and the C programming language with a focus on the low-level interrelationships and impacts on performance. Topics include the virtual address space and virtual memory, the heap and dynamic memory management, the memory hierarchy and caching, assembly language and the stack, communication and interrupts/signals, compiling and assemblers/linkers.", - "keywords": [ - "computer", - "science", - "engineering", - "electrical", - "machine", - "programming" - ], - "name": "Machine Organization and Programming", - "number": "COMPSCI_354", - "requisites": [ - [ - "COMPSCI_252" - ], - [ - "COMPSCI_300" - ] - ], - "sections": [ - { - "instructor": "James Skrentny", - "location": "132 Noland Hall", - "subsections": [], - "time": { - "thursday": "2:30pm - 3:45pm", - "tuesday": "2:30pm - 3:45pm" - }, - "number": "LEC_001" - }, - { - "instructor": "James Skrentny", - "location": "132 Noland Hall", - "subsections": [], - "time": { - "thursday": "4:00pm - 5:15pm", - "tuesday": "4:00pm - 5:15pm" - }, - "number": "LEC_002" - } - ], - "subject": "Computer Science" - }, - { - "credits": 4, - "description": "Introduction. Stoichiometry and the mole concept, the behavior of gases, liquids and solids, thermochemistry, electronic structure of atoms and chemical bonding, descriptive chemistry of selected elements and compounds, intermolecular forces. For students taking one year or more of college chemistry; serves as a prereq for CHEM_104; lecture, lab and discussion.", - "keywords": [ - "chemistry" - ], - "name": "General Chemistry I", - "number": "CHEM_103", - "requisites": [], - "sections": [ - { - "instructor": "Unknown", - "location": "B10 Ingraham Hall", - "subsections": [ - { - "location": "49 Sellery Residence Hall", - "time": { - "monday": "3:30pm - 4:20pm", - "wednesday": "3:30pm - 4:20pm" - }, - "number": "DIS_301" - }, - { - "location": "2307 Chemistry Building", - "time": { - "monday": "4:35pm - 5:25pm", - "wednesday": "4:35pm - 5:25pm" - }, - "number": "DIS_302" - }, - { - "location": "123 Van Hise Hall", - "time": { - "monday": "1:20pm - 2:10pm", - "wednesday": "1:20pm - 2:10pm" - }, - "number": "DIS_303" - }, - { - "location": "123 Van Hise Hall", - "time": { - "monday": "2:25pm - 3:15pm", - "wednesday": "2:25pm - 3:15pm" - }, - "number": "DIS_304" - } - ], - "time": { - "friday": "11:00am - 11:50am", - "monday": "11:00am - 11:50am", - "wednesday": "11:00am - 11:50am" - }, - "number": "LEC_001" - } - ], - "subject": "Chemistry" - }, - { - "credits": 3, - "description": "This course introduces students to the software development of user interfaces (UIs). Topics covered include state-of-the-art (1) UI paradigms, such as event-driven interfaces, direct-manipulation interfaces, and dialogue-based interaction; (2) methods for capturing, interpreting, and responding to different forms of user input and states, including pointing, text entry, speech, touch, gestures, user activity, context, and physiological states; and (3) platform-specific UI development APIs, frameworks, and toolkits for platforms including web/mobile/desktop interfaces, natural user interfaces, and voice user interfaces. Through readings, lectures, and hands-on-activities, students will learn about the fundamental concepts, technologies, and methods in building user interfaces. Assignments will provide an opportunity to gain hands-on experience in the use of state-of-the-art UI development tools and build a UI development portfolio.", - "keywords": [ - "computer", - "science", - "building", - "user", - "interface", - "interfaces", - "design", - "ui" - ], - "name": "Building User Interfaces", - "number": "COMPSCI_639", - "requisites": [ - [ - "COMPSCI_300" - ] - ], - "sections": [ - { - "instructor": "Bilge Mutlu", - "location": "1221 Computer Sciences and Statistics", - "subsections": [], - "time": { - "thursday": "1:00pm - 2:15pm", - "tuesday": "1:00pm - 2:15pm" - }, - "number": "LEC_002" - } - ], - "subject": "Computer Science" - }, - { - "credits": 3, - "description": "Focuses on the role that psychological principles, research evidence and social science play in the laws of U.S. society, especially in the policies and mechanisms of social control of human behavior. The course will address the ways that society defines membership, and the role of psychology in how it determines who should be excluded or restricted from open society, in order to maintain a more civil society. In addition to learning the factual information about how selected processes work in the legal and social context, students will be asked to consider the role they can play as citizens in supporting or changing these social processes. The course will take a particular interest in psycholegal issues \"in action\" and in learning about the clinical-legal processes used to determine the disposition of individuals considered marginal in society. Finally, the course will address the mechanisms that are used to exclude individuals from open society through criminal and civil court processes, the role of psychology as a science, and the role of psychologists as behavioral experts in criminal and civil courts, and in shaping social policies.", - "keywords": [ - "psychology", - "science", - "law", - "social", - "policy", - "behavior" - ], - "name": "Psychology, Law, and Social Policy", - "number": "PSYCH_401", - "requisites": [ - [ - "PSYCH_202" - ] - ], - "sections": [ - { - "instructor": "Gregory Van Rybroek", - "location": "121 Brogden Psychology Building", - "subsections": [], - "time": { - "monday": "4:00pm - 5:15pm", - "wednesday": "4:00pm - 5:15pm" - }, - "number": "LEC_001" - } - ], - "subject": "Psychology" - }, - { - "credits": 3, - "description": "Basic concepts of logic, sets, partial order and other relations, and functions. Basic concepts of mathematics (definitions, proofs, sets, functions, and relations) with a focus on discrete structures: integers, bits, strings, trees, and graphs. Propositional logic, Boolean algebra, and predicate logic. Mathematical induction and recursion. Invariants and algorithmic correctness. Recurrences and asymptotic growth analysis. Fundamentals of counting.", - "keywords": [ - "computer", - "science", - "math", - "mathematics", - "discrete", - "logic", - "algorithm", - "algorithms" - ], - "name": "Introduction To Discrete Mathematics", - "number": "COMPSCI_240", - "requisites": [ - [ - "MATH_221" - ] - ], - "sections": [ - { - "instructor": "Beck Hasti", - "location": "105 Brogden Psychology Building", - "subsections": [ - { - "location": "1257 Computer Sciences and Statistics", - "time": { - "tuesday": "8:50am - 9:40am" - }, - "number": "DIS_310" - }, - { - "location": "1257 Computer Sciences and Statistics", - "time": { - "thursday": "8:50am - 9:40am" - }, - "number": "DIS_311" - }, - { - "location": "3024 Engineering Hall", - "time": { - "tuesday": "9:55am - 10:45am" - }, - "number": "DIS_312" - }, - { - "location": "2345 Engineering Hall", - "time": { - "thursday": "9:55am - 10:45am" - }, - "number": "DIS_313" - }, - { - "location": "2535 Engineering Hall", - "time": { - "tuesday": "11:00am - 11:50am" - }, - "number": "DIS_314" - }, - { - "location": "2535 Engineering Hall", - "time": { - "thursday": "11:00am - 11:50am" - }, - "number": "DIS_315" - }, - { - "location": "B309 Van Vleck Hall", - "time": { - "tuesday": "9:55am - 10:45am" - }, - "number": "DIS_316" - } - ], - "time": { - "friday": "9:55am - 10:45am", - "monday": "9:55am - 10:45am", - "wednesday": "9:55am - 10:45am" - }, - "number": "LEC_001" - }, - { - "instructor": "Beck Hasti", - "location": "132 Noland Hall", - "subsections": [ - { - "location": "B211 Van Vleck Hall", - "time": { - "thursday": "11:00am - 11:50am" - }, - "number": "DIS_320" - }, - { - "location": "B211 Van Vleck Hall", - "time": { - "tuesday": "12:05pm - 12:55pm" - }, - "number": "DIS_321" - }, - { - "location": "2255 Engineering Hall", - "time": { - "thursday": "12:05pm - 12:55pm" - }, - "number": "DIS_322" - }, - { - "location": "2349 Engineering Hall", - "time": { - "tuesday": "1:20pm - 2:10pm" - }, - "number": "DIS_323" - }, - { - "location": "1263 Computer Sciences and Statistics", - "time": { - "thursday": "1:20pm - 2:10pm" - }, - "number": "DIS_324" - }, - { - "location": "3418 Engineering Hall", - "time": { - "tuesday": "2:25pm - 3:15pm" - }, - "number": "DIS_325" - }, - { - "location": "3418 Engineering Hall", - "time": { - "thursday": "2:25pm - 3:15pm" - }, - "number": "DIS_326" - } - ], - "time": { - "friday": "1:20pm - 2:10pm", - "monday": "1:20pm - 2:10pm", - "wednesday": "1:20pm - 2:10pm" - }, - "number": "LEC_002" - }, - { - "instructor": "Beck Hasti", - "location": "168 Noland Hall", - "subsections": [ - { - "location": "1263 Computer Sciences and Statistics", - "time": { - "tuesday": "8:50am - 9:40am" - }, - "number": "DIS_330" - }, - { - "location": "1263 Computer Sciences and Statistics", - "time": { - "tuesday": "1:20pm - 2:10pm" - }, - "number": "DIS_331" - }, - { - "location": "3024 Engineering Hall", - "time": { - "thursday": "9:55am - 10:45am" - }, - "number": "DIS_332" - }, - { - "location": "2349 Engineering Hall", - "time": { - "thursday": "12:05am - 12:55am" - }, - "number": "DIS_333" - } - ], - "time": { - "friday": "2:25pm - 3:15pm", - "monday": "2:25pm - 3:15pm", - "wednesday": "2:25pm - 3:15pm" - }, - "number": "LEC_003" - } - ], - "subject": "Computer Science" - }, - { - "credits": 3, - "description": "Graphical and numerical exploration of data; standard errors; distributions for statistical models including binomial, Poisson, normal; estimation; hypothesis testing; randomization tests; basic principles of experimental design; regression; ANOVA; categorical data analysis; goodness of fit; application. (intended for students wishing to take additional statistics courses).", - "keywords": [ - "statistics", - "statistical", - "math", - "mathematics", - "methods" - ], - "name": "Accelerated Introduction to Statistical Methods", - "number": "STATS_302", - "requisites": [ - [ - "MATH_221" - ] - ], - "sections": [ - { - "instructor": "Unknown", - "location": "331 Service Memorial Institute", - "subsections": [ - { - "location": "212 Educational Sciences", - "time": { - "tuesday": "1:20pm - 2:10pm" - }, - "number": "DIS_311" - }, - { - "location": "1313 Sterling Hall", - "time": { - "wednesday": "7:45am - 8:35am" - }, - "number": "DIS_312" - }, - { - "location": "1313 Sterling Hall", - "time": { - "wednesday": "11:00am - 11:50am" - }, - "number": "DIS_313" - } - ], - "time": { - "monday": "4:00pm - 5:15pm", - "wednesday": "4:00pm - 5:15pm" - }, - "number": "LEC_001" - } - ], - "subject": "Statistics" - } -] \ No newline at end of file diff --git a/f22/andy_lec_notes/lec29_Nov16_Web1/cs200_data.json b/f22/andy_lec_notes/lec29_Nov16_Web1/cs200_data.json deleted file mode 100644 index e64c1de13a45fbc1a5053c0a4a22defc7cb1c6cb..0000000000000000000000000000000000000000 --- a/f22/andy_lec_notes/lec29_Nov16_Web1/cs200_data.json +++ /dev/null @@ -1,181 +0,0 @@ -{ - "credits": 3, - "description": "Learn the process of incrementally developing small (200-500 lines) programs along with the fundamental Computer Science topics. These topics include: problem abstraction and decomposition, the edit-compile-run cycle, using variables of primitive and more complex data types, conditional and loop-based flow control, basic testing and debugging techniques, how to define and call functions (methods), and IO processing techniques. Also teaches and reinforces good programming practices including the use of a consistent style, and meaningful documentation. Intended for students who have no prior programming experience.", - "keywords": [ - "computer", - "science", - "programming", - "java" - ], - "name": "Programming 1", - "number": "COMPSCI_200", - "requisites": [], - "sections": [ - { - "instructor": "Jim Williams", - "location": "132 Noland Hall", - "subsections": [ - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "wednesday": "9:30am - 10:45am" - }, - "number": "LAB_311" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "wednesday": "11:00am - 12:15pm" - }, - "number": "LAB_312" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "wednesday": "2:30pm - 3:45pm" - }, - "number": "LAB_314" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "wednesday": "4:00pm - 5:15pm" - }, - "number": "LAB_315" - } - ], - "time": { - "thursday": "8:00am - 9:15am", - "tuesday": "8:00am - 9:15am" - }, - "number": "LEC_001" - }, - { - "instructor": "Jim Williams", - "location": "132 Noland Hall", - "subsections": [ - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "wednesday": "9:30am - 10:45am" - }, - "number": "LAB_321" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "wednesday": "1:00pm - 2:15pm" - }, - "number": "LAB_323" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "wednesday": "2:30pm - 3:45pm" - }, - "number": "LAB_324" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "wednesday": "4:00pm - 5:15pm" - }, - "number": "LAB_325" - } - ], - "time": { - "thursday": "11:00am - 12:15pm", - "tuesday": "11:00am - 12:15pm" - }, - "number": "LEC_002" - }, - { - "instructor": "Marc Renault", - "location": "113 Brogden Psychology Building", - "subsections": [ - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "tuesday": "9:30am - 10:45am" - }, - "number": "LAB_331" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "tuesday": "11:00am - 12:15pm" - }, - "number": "LAB_332" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "tuesday": "1:00pm - 2:15pm" - }, - "number": "LAB_333" - }, - { - "location": "1350 Computer Sciences and Statistics", - "time": { - "tuesday": "2:30pm - 3:45pm" - }, - "number": "LAB_334" - } - ], - "time": { - "friday": "1:20pm - 2:10pm", - "monday": "1:20pm - 2:10pm", - "wednesday": "1:20pm - 2:10pm" - }, - "number": "LEC_003" - }, - { - "instructor": "Marc Renault", - "location": "113 Brogden Psychology Building", - "subsections": [ - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "tuesday": "9:30am - 10:45am" - }, - "number": "LAB_341" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "tuesday": "11:00am - 12:15pm" - }, - "number": "LAB_342" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "tuesday": "1:00pm - 2:15pm" - }, - "number": "LAB_343" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "tuesday": "2:30pm - 3:45pm" - }, - "number": "LAB_344" - }, - { - "location": "1370 Computer Sciences and Statistics", - "time": { - "tuesday": "4:00pm - 5:15pm" - }, - "number": "LAB_345" - } - ], - "time": { - "friday": "3:30pm - 4:20pm", - "monday": "3:30pm - 4:20pm", - "wednesday": "3:30pm - 4:20pm" - }, - "number": "LEC_004" - } - ], - "subject": "Computer Science" -} \ No newline at end of file diff --git a/f22/andy_lec_notes/lec29_Nov16_Web1/lec29_template.ipynb b/f22/andy_lec_notes/lec29_Nov16_Web1/lec29_template.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..9c96cb5427ee3f77cf41570088f096d74587cd88 --- /dev/null +++ b/f22/andy_lec_notes/lec29_Nov16_Web1/lec29_template.ipynb @@ -0,0 +1,1862 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "import requests # We will learn about this today!\n", + "import json\n", + "import pandas as pd\n", + "from pandas import Series, DataFrame" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "<div>\n", + "<style scoped>\n", + " .dataframe tbody tr th:only-of-type {\n", + " vertical-align: middle;\n", + " }\n", + "\n", + " .dataframe tbody tr th {\n", + " vertical-align: top;\n", + " }\n", + "\n", + " .dataframe thead th {\n", + " text-align: right;\n", + " }\n", + "</style>\n", + "<table border=\"1\" class=\"dataframe\">\n", + " <thead>\n", + " <tr style=\"text-align: right;\">\n", + " <th></th>\n", + " <th>Title</th>\n", + " <th>Genre</th>\n", + " <th>Director</th>\n", + " <th>Cast</th>\n", + " <th>Year</th>\n", + " <th>Runtime</th>\n", + " <th>Rating</th>\n", + " <th>Revenue</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>1063</th>\n", + " <td>Guardians of the Galaxy Vol. 2</td>\n", + " <td>Action, Adventure, Comedy</td>\n", + " <td>James Gunn</td>\n", + " <td>Chris Pratt, Zoe Saldana, Dave Bautista, Vin D...</td>\n", + " <td>2017</td>\n", + " <td>136</td>\n", + " <td>7.6</td>\n", + " <td>389.81</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1064</th>\n", + " <td>Baby Driver</td>\n", + " <td>Action, Crime, Drama</td>\n", + " <td>Edgar Wright</td>\n", + " <td>Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon...</td>\n", + " <td>2017</td>\n", + " <td>113</td>\n", + " <td>7.6</td>\n", + " <td>107.83</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1065</th>\n", + " <td>Only the Brave</td>\n", + " <td>Action, Biography, Drama</td>\n", + " <td>Joseph Kosinski</td>\n", + " <td>Josh Brolin, Miles Teller, Jeff Bridges, Jenni...</td>\n", + " <td>2017</td>\n", + " <td>134</td>\n", + " <td>7.6</td>\n", + " <td>18.34</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1066</th>\n", + " <td>Incredibles 2</td>\n", + " <td>Animation, Action, Adventure</td>\n", + " <td>Brad Bird</td>\n", + " <td>Craig T. Nelson, Holly Hunter, Sarah Vowell, H...</td>\n", + " <td>2018</td>\n", + " <td>118</td>\n", + " <td>7.6</td>\n", + " <td>608.58</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1067</th>\n", + " <td>A Star Is Born</td>\n", + " <td>Drama, Music, Romance</td>\n", + " <td>Bradley Cooper</td>\n", + " <td>Lady Gaga, Bradley Cooper, Sam Elliott, Greg G...</td>\n", + " <td>2018</td>\n", + " <td>136</td>\n", + " <td>7.6</td>\n", + " <td>215.29</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "</div>" + ], + "text/plain": [ + " Title Genre \\\n", + "1063 Guardians of the Galaxy Vol. 2 Action, Adventure, Comedy \n", + "1064 Baby Driver Action, Crime, Drama \n", + "1065 Only the Brave Action, Biography, Drama \n", + "1066 Incredibles 2 Animation, Action, Adventure \n", + "1067 A Star Is Born Drama, Music, Romance \n", + "\n", + " Director Cast \\\n", + "1063 James Gunn Chris Pratt, Zoe Saldana, Dave Bautista, Vin D... \n", + "1064 Edgar Wright Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon... \n", + "1065 Joseph Kosinski Josh Brolin, Miles Teller, Jeff Bridges, Jenni... \n", + "1066 Brad Bird Craig T. Nelson, Holly Hunter, Sarah Vowell, H... \n", + "1067 Bradley Cooper Lady Gaga, Bradley Cooper, Sam Elliott, Greg G... \n", + "\n", + " Year Runtime Rating Revenue \n", + "1063 2017 136 7.6 389.81 \n", + "1064 2017 113 7.6 107.83 \n", + "1065 2017 134 7.6 18.34 \n", + "1066 2018 118 7.6 608.58 \n", + "1067 2018 136 7.6 215.29 " + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Warmup 1: Read the data from \"new_movie_data.csv\" into a pandas DataFrame called \"movies\"\n", + "movies = None\n", + "movies.tail()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2006 to 2020\n" + ] + } + ], + "source": [ + "# Warmup 2: What years does this new movie dataset cover? (min and max?)\n", + "year_min = None\n", + "year_max = None\n", + "print(year_min, \"to\", year_max)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15300000.0" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Warmup 3a: What does this function do?\n", + "def format_revenue(revenue):\n", + " if type(revenue) == float: # need this in here if we run code multiple times\n", + " return revenue\n", + " elif revenue[-1] == 'M': # some have an \"M\" at the end\n", + " return float(revenue[:-1]) * 1e6\n", + " else: # otherwise, assume millions.\n", + " return float(revenue) * 1e6\n", + " \n", + "print(format_revenue(\"15.3M\"))\n", + "# how else should we test this? " + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "<div>\n", + "<style scoped>\n", + " .dataframe tbody tr th:only-of-type {\n", + " vertical-align: middle;\n", + " }\n", + "\n", + " .dataframe tbody tr th {\n", + " vertical-align: top;\n", + " }\n", + "\n", + " .dataframe thead th {\n", + " text-align: right;\n", + " }\n", + "</style>\n", + "<table border=\"1\" class=\"dataframe\">\n", + " <thead>\n", + " <tr style=\"text-align: right;\">\n", + " <th></th>\n", + " <th>Title</th>\n", + " <th>Genre</th>\n", + " <th>Director</th>\n", + " <th>Cast</th>\n", + " <th>Year</th>\n", + " <th>Runtime</th>\n", + " <th>Rating</th>\n", + " <th>Revenue</th>\n", + " <th>CountableRevenue</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>0</th>\n", + " <td>Guardians of the Galaxy</td>\n", + " <td>Action,Adventure,Sci-Fi</td>\n", + " <td>James Gunn</td>\n", + " <td>Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...</td>\n", + " <td>2014</td>\n", + " <td>121</td>\n", + " <td>8.1</td>\n", + " <td>333.13</td>\n", + " <td>333130000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1</th>\n", + " <td>Prometheus</td>\n", + " <td>Adventure,Mystery,Sci-Fi</td>\n", + " <td>Ridley Scott</td>\n", + " <td>Noomi Rapace, Logan Marshall-Green, Michael ...</td>\n", + " <td>2012</td>\n", + " <td>124</td>\n", + " <td>7.0</td>\n", + " <td>126.46M</td>\n", + " <td>126460000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>2</th>\n", + " <td>Split</td>\n", + " <td>Horror,Thriller</td>\n", + " <td>M. Night Shyamalan</td>\n", + " <td>James McAvoy, Anya Taylor-Joy, Haley Lu Richar...</td>\n", + " <td>2016</td>\n", + " <td>117</td>\n", + " <td>7.3</td>\n", + " <td>138.12M</td>\n", + " <td>138120000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>3</th>\n", + " <td>Sing</td>\n", + " <td>Animation,Comedy,Family</td>\n", + " <td>Christophe Lourdelet</td>\n", + " <td>Matthew McConaughey,Reese Witherspoon, Seth Ma...</td>\n", + " <td>2016</td>\n", + " <td>108</td>\n", + " <td>7.2</td>\n", + " <td>270.32</td>\n", + " <td>270320000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>4</th>\n", + " <td>Suicide Squad</td>\n", + " <td>Action,Adventure,Fantasy</td>\n", + " <td>David Ayer</td>\n", + " <td>Will Smith, Jared Leto, Margot Robbie, Viola D...</td>\n", + " <td>2016</td>\n", + " <td>123</td>\n", + " <td>6.2</td>\n", + " <td>325.02</td>\n", + " <td>325020000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>...</th>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1063</th>\n", + " <td>Guardians of the Galaxy Vol. 2</td>\n", + " <td>Action, Adventure, Comedy</td>\n", + " <td>James Gunn</td>\n", + " <td>Chris Pratt, Zoe Saldana, Dave Bautista, Vin D...</td>\n", + " <td>2017</td>\n", + " <td>136</td>\n", + " <td>7.6</td>\n", + " <td>389.81</td>\n", + " <td>389810000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1064</th>\n", + " <td>Baby Driver</td>\n", + " <td>Action, Crime, Drama</td>\n", + " <td>Edgar Wright</td>\n", + " <td>Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon...</td>\n", + " <td>2017</td>\n", + " <td>113</td>\n", + " <td>7.6</td>\n", + " <td>107.83</td>\n", + " <td>107830000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1065</th>\n", + " <td>Only the Brave</td>\n", + " <td>Action, Biography, Drama</td>\n", + " <td>Joseph Kosinski</td>\n", + " <td>Josh Brolin, Miles Teller, Jeff Bridges, Jenni...</td>\n", + " <td>2017</td>\n", + " <td>134</td>\n", + " <td>7.6</td>\n", + " <td>18.34</td>\n", + " <td>18340000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1066</th>\n", + " <td>Incredibles 2</td>\n", + " <td>Animation, Action, Adventure</td>\n", + " <td>Brad Bird</td>\n", + " <td>Craig T. Nelson, Holly Hunter, Sarah Vowell, H...</td>\n", + " <td>2018</td>\n", + " <td>118</td>\n", + " <td>7.6</td>\n", + " <td>608.58</td>\n", + " <td>608580000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1067</th>\n", + " <td>A Star Is Born</td>\n", + " <td>Drama, Music, Romance</td>\n", + " <td>Bradley Cooper</td>\n", + " <td>Lady Gaga, Bradley Cooper, Sam Elliott, Greg G...</td>\n", + " <td>2018</td>\n", + " <td>136</td>\n", + " <td>7.6</td>\n", + " <td>215.29</td>\n", + " <td>215290000.0</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "<p>1068 rows × 9 columns</p>\n", + "</div>" + ], + "text/plain": [ + " Title Genre \\\n", + "0 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 Split Horror,Thriller \n", + "3 Sing Animation,Comedy,Family \n", + "4 Suicide Squad Action,Adventure,Fantasy \n", + "... ... ... \n", + "1063 Guardians of the Galaxy Vol. 2 Action, Adventure, Comedy \n", + "1064 Baby Driver Action, Crime, Drama \n", + "1065 Only the Brave Action, Biography, Drama \n", + "1066 Incredibles 2 Animation, Action, Adventure \n", + "1067 A Star Is Born Drama, Music, Romance \n", + "\n", + " Director Cast \\\n", + "0 James Gunn Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... \n", + "1 Ridley Scott Noomi Rapace, Logan Marshall-Green, Michael ... \n", + "2 M. Night Shyamalan James McAvoy, Anya Taylor-Joy, Haley Lu Richar... \n", + "3 Christophe Lourdelet Matthew McConaughey,Reese Witherspoon, Seth Ma... \n", + "4 David Ayer Will Smith, Jared Leto, Margot Robbie, Viola D... \n", + "... ... ... \n", + "1063 James Gunn Chris Pratt, Zoe Saldana, Dave Bautista, Vin D... \n", + "1064 Edgar Wright Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon... \n", + "1065 Joseph Kosinski Josh Brolin, Miles Teller, Jeff Bridges, Jenni... \n", + "1066 Brad Bird Craig T. Nelson, Holly Hunter, Sarah Vowell, H... \n", + "1067 Bradley Cooper Lady Gaga, Bradley Cooper, Sam Elliott, Greg G... \n", + "\n", + " Year Runtime Rating Revenue CountableRevenue \n", + "0 2014 121 8.1 333.13 333130000.0 \n", + "1 2012 124 7.0 126.46M 126460000.0 \n", + "2 2016 117 7.3 138.12M 138120000.0 \n", + "3 2016 108 7.2 270.32 270320000.0 \n", + "4 2016 123 6.2 325.02 325020000.0 \n", + "... ... ... ... ... ... \n", + "1063 2017 136 7.6 389.81 389810000.0 \n", + "1064 2017 113 7.6 107.83 107830000.0 \n", + "1065 2017 134 7.6 18.34 18340000.0 \n", + "1066 2018 118 7.6 608.58 608580000.0 \n", + "1067 2018 136 7.6 215.29 215290000.0 \n", + "\n", + "[1068 rows x 9 columns]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Warmup 3b: Using the above function, create a new column called\n", + "# \"CountableRevenue\" with the revenue as a float.\n", + "\n", + "movies[\"CountableRevenue\"] = movies['Revenue'].apply(...)\n", + "movies.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "<div>\n", + "<style scoped>\n", + " .dataframe tbody tr th:only-of-type {\n", + " vertical-align: middle;\n", + " }\n", + "\n", + " .dataframe tbody tr th {\n", + " vertical-align: top;\n", + " }\n", + "\n", + " .dataframe thead th {\n", + " text-align: right;\n", + " }\n", + "</style>\n", + "<table border=\"1\" class=\"dataframe\">\n", + " <thead>\n", + " <tr style=\"text-align: right;\">\n", + " <th></th>\n", + " <th>Title</th>\n", + " <th>Genre</th>\n", + " <th>Director</th>\n", + " <th>Cast</th>\n", + " <th>Year</th>\n", + " <th>Runtime</th>\n", + " <th>Rating</th>\n", + " <th>Revenue</th>\n", + " <th>CountableRevenue</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>0</th>\n", + " <td>Guardians of the Galaxy</td>\n", + " <td>Action,Adventure,Sci-Fi</td>\n", + " <td>James Gunn</td>\n", + " <td>Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S...</td>\n", + " <td>2014</td>\n", + " <td>121</td>\n", + " <td>8.1</td>\n", + " <td>333.13</td>\n", + " <td>333130000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1</th>\n", + " <td>Prometheus</td>\n", + " <td>Adventure,Mystery,Sci-Fi</td>\n", + " <td>Ridley Scott</td>\n", + " <td>Noomi Rapace, Logan Marshall-Green, Michael ...</td>\n", + " <td>2012</td>\n", + " <td>124</td>\n", + " <td>7.0</td>\n", + " <td>126.46M</td>\n", + " <td>126460000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>2</th>\n", + " <td>Split</td>\n", + " <td>Horror,Thriller</td>\n", + " <td>M. Night Shyamalan</td>\n", + " <td>James McAvoy, Anya Taylor-Joy, Haley Lu Richar...</td>\n", + " <td>2016</td>\n", + " <td>117</td>\n", + " <td>7.3</td>\n", + " <td>138.12M</td>\n", + " <td>138120000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>3</th>\n", + " <td>Sing</td>\n", + " <td>Animation,Comedy,Family</td>\n", + " <td>Christophe Lourdelet</td>\n", + " <td>Matthew McConaughey,Reese Witherspoon, Seth Ma...</td>\n", + " <td>2016</td>\n", + " <td>108</td>\n", + " <td>7.2</td>\n", + " <td>270.32</td>\n", + " <td>270320000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>4</th>\n", + " <td>Suicide Squad</td>\n", + " <td>Action,Adventure,Fantasy</td>\n", + " <td>David Ayer</td>\n", + " <td>Will Smith, Jared Leto, Margot Robbie, Viola D...</td>\n", + " <td>2016</td>\n", + " <td>123</td>\n", + " <td>6.2</td>\n", + " <td>325.02</td>\n", + " <td>325020000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>...</th>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " <td>...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1063</th>\n", + " <td>Guardians of the Galaxy Vol. 2</td>\n", + " <td>Action, Adventure, Comedy</td>\n", + " <td>James Gunn</td>\n", + " <td>Chris Pratt, Zoe Saldana, Dave Bautista, Vin D...</td>\n", + " <td>2017</td>\n", + " <td>136</td>\n", + " <td>7.6</td>\n", + " <td>389.81</td>\n", + " <td>389810000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1064</th>\n", + " <td>Baby Driver</td>\n", + " <td>Action, Crime, Drama</td>\n", + " <td>Edgar Wright</td>\n", + " <td>Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon...</td>\n", + " <td>2017</td>\n", + " <td>113</td>\n", + " <td>7.6</td>\n", + " <td>107.83</td>\n", + " <td>107830000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1065</th>\n", + " <td>Only the Brave</td>\n", + " <td>Action, Biography, Drama</td>\n", + " <td>Joseph Kosinski</td>\n", + " <td>Josh Brolin, Miles Teller, Jeff Bridges, Jenni...</td>\n", + " <td>2017</td>\n", + " <td>134</td>\n", + " <td>7.6</td>\n", + " <td>18.34</td>\n", + " <td>18340000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1066</th>\n", + " <td>Incredibles 2</td>\n", + " <td>Animation, Action, Adventure</td>\n", + " <td>Brad Bird</td>\n", + " <td>Craig T. Nelson, Holly Hunter, Sarah Vowell, H...</td>\n", + " <td>2018</td>\n", + " <td>118</td>\n", + " <td>7.6</td>\n", + " <td>608.58</td>\n", + " <td>608580000.0</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1067</th>\n", + " <td>A Star Is Born</td>\n", + " <td>Drama, Music, Romance</td>\n", + " <td>Bradley Cooper</td>\n", + " <td>Lady Gaga, Bradley Cooper, Sam Elliott, Greg G...</td>\n", + " <td>2018</td>\n", + " <td>136</td>\n", + " <td>7.6</td>\n", + " <td>215.29</td>\n", + " <td>215290000.0</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "<p>1068 rows × 9 columns</p>\n", + "</div>" + ], + "text/plain": [ + " Title Genre \\\n", + "0 Guardians of the Galaxy Action,Adventure,Sci-Fi \n", + "1 Prometheus Adventure,Mystery,Sci-Fi \n", + "2 Split Horror,Thriller \n", + "3 Sing Animation,Comedy,Family \n", + "4 Suicide Squad Action,Adventure,Fantasy \n", + "... ... ... \n", + "1063 Guardians of the Galaxy Vol. 2 Action, Adventure, Comedy \n", + "1064 Baby Driver Action, Crime, Drama \n", + "1065 Only the Brave Action, Biography, Drama \n", + "1066 Incredibles 2 Animation, Action, Adventure \n", + "1067 A Star Is Born Drama, Music, Romance \n", + "\n", + " Director Cast \\\n", + "0 James Gunn Chris Pratt, Vin Diesel, Bradley Cooper, Zoe S... \n", + "1 Ridley Scott Noomi Rapace, Logan Marshall-Green, Michael ... \n", + "2 M. Night Shyamalan James McAvoy, Anya Taylor-Joy, Haley Lu Richar... \n", + "3 Christophe Lourdelet Matthew McConaughey,Reese Witherspoon, Seth Ma... \n", + "4 David Ayer Will Smith, Jared Leto, Margot Robbie, Viola D... \n", + "... ... ... \n", + "1063 James Gunn Chris Pratt, Zoe Saldana, Dave Bautista, Vin D... \n", + "1064 Edgar Wright Ansel Elgort, Jon Bernthal, Jon Hamm, Eiza Gon... \n", + "1065 Joseph Kosinski Josh Brolin, Miles Teller, Jeff Bridges, Jenni... \n", + "1066 Brad Bird Craig T. Nelson, Holly Hunter, Sarah Vowell, H... \n", + "1067 Bradley Cooper Lady Gaga, Bradley Cooper, Sam Elliott, Greg G... \n", + "\n", + " Year Runtime Rating Revenue CountableRevenue \n", + "0 2014 121 8.1 333.13 333130000.0 \n", + "1 2012 124 7.0 126.46M 126460000.0 \n", + "2 2016 117 7.3 138.12M 138120000.0 \n", + "3 2016 108 7.2 270.32 270320000.0 \n", + "4 2016 123 6.2 325.02 325020000.0 \n", + "... ... ... ... ... ... \n", + "1063 2017 136 7.6 389.81 389810000.0 \n", + "1064 2017 113 7.6 107.83 107830000.0 \n", + "1065 2017 134 7.6 18.34 18340000.0 \n", + "1066 2018 118 7.6 608.58 608580000.0 \n", + "1067 2018 136 7.6 215.29 215290000.0 \n", + "\n", + "[1068 rows x 9 columns]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Warmup 4: What are the top 10 highest-revenue movies?\n", + "\n", + "movies.sort_values(by=None, ascending=None).head(10)\n", + "movies" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Pandas tutorial\n", + "https://www.w3schools.com/python/pandas/default.asp\n", + "\n", + "### Pandas cheat sheet\n", + "https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Lecture 29: Web 1 - Getting Data\n", + "Learning Objectives\n", + "\n", + "- Make a request for data using `requests.get(URL)`\n", + "- Check the status of a request/response\n", + "- Extract the text of a response\n", + "- Create a json file from a response\n", + "- State and practice good etiquette when getting data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Make a request for data using `requests.get(URL)`\n", + "- URL: https://www.msyamkumar.com/hello.txt" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<class 'requests.models.Response'>\n", + "200\n", + "Hello CS220 / CS319 students! Welcome to my website. Hope you are staying safe and healthy!\n", + "\n" + ] + } + ], + "source": [ + "url = \"https://www.msyamkumar.com/hello.txt\"\n", + "r = requests.get(url) # r is the response\n", + "print(type(r))\n", + "print(r.status_code)\n", + "print(r.text)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### HTTP Status Codes you need to know\n", + "\n", + "- 200: success\n", + "- 404: not found\n", + "\n", + "Here is a list of all status codes, you do NOT need to memorize it\n", + "\n", + "https://en.wikipedia.org/wiki/List_of_HTTP_status_codes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Additional (not required) info about Request objects\n", + "https://www.w3schools.com/python/module_requests.asp" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "404\n", + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", + "<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>meena/hello.txttttt</Key><RequestId>CTFZBRA30B4C5552</RequestId><HostId>iag9ELL1ZQre0Ie5lvl0Bi1rZrLZ4jaVY9+ynWsiU3RutM4OTBQ/xh7S0w4pU3EGqPY2hzyC55I=</HostId></Error>\n" + ] + } + ], + "source": [ + "# Q: What if the web site does not exist?\n", + "typo_url = \"https://www.msyamkumar.com/hello.txttttt\"\n", + "r = requests.get(typo_url)\n", + "print(r.status_code)\n", + "print(r.text)\n", + "\n", + "# A: We get a 404 (client error)\n", + "# A: we get text, but the text is not from the client\n", + "# so we have to make sure we check the status of our request" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Check the status of a request/response\n" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "404\n", + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", + "<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>meena/hello.txttttt</Key><RequestId>892JC5CJRQZ058DS</RequestId><HostId>dAM8G4UhwnkiUf2eQH2sNv81QQ+YWiyu1mmsA9XkVI12EPd+7wFRbqv1hymiO2FStf/Y7TUheIo=</HostId></Error>\n" + ] + } + ], + "source": [ + "# We can check for a status_code error by using an assert\n", + "typo_url = \"https://www.msyamkumar.com/hello.txttttt\"\n", + "r = requests.get(typo_url)\n", + "print(r.status_code)\n", + "assert True # change this\n", + "\n", + "print(r.text)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Instead of using an assert, we often use raise_for_status()\n", + "r = requests.get(typo_url)\n", + "r.raise_for_status() #similar to asserting r.status_code == 200\n", + "r.text\n", + "\n", + "# Note the error you get.... We will use this in the next cell" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Let's try to catch that error \n", + "\n", + "try:\n", + "\n", + "except:\n", + " print(\"oops!!\", e)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# we often need to prepend the names of exceptions with the name of the module\n", + "# fix the error from above\n", + "\n", + "try:\n", + "\n", + "except:\n", + " print(\"oops!!\", e)\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create a json file from a response\n", + "\n", + "- URL: https://www.msyamkumar.com/scores.json\n", + "- `json.load` (FILE_OBJECT)\n", + "- `json.loads` (STRING)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# GETting a JSON file, the long way\n", + "url = \"https://www.msyamkumar.com/scores.json\"\n", + "r = requests.get(url)\n", + "r.raise_for_status()\n", + "urltext = r.text\n", + "print(urltext)\n", + "d = json.loads(urltext)\n", + "print(type(d), d)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# GETting a JSON file, the shortcut way\n", + "url = \"https://www.msyamkumar.com/scores.json\"\n", + "#Shortcut to bypass using json.loads()\n", + "r = requests.get(url)\n", + "r.raise_for_status()\n", + "\n", + "d2 = None\n", + "\n", + "print(type(d2), d2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Good GET Etiquette\n", + "\n", + "Don't make a lot of requests to the same server all at once.\n", + " - Requests use up the server's time\n", + " - Major websites will often ban users who make too many requests\n", + " - You can break a server....similar to DDoS attacks (DON'T DO THIS)\n", + " \n", + "In CS220 we will usually give you a link to a copied file to avoid overloading the site.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## DEMO: Get Weather Data and play with it\n", + "\n", + "https://api.weather.gov/gridpoints/MKX/37,63/forecast" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['@context', 'type', 'geometry', 'properties'])" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "url = \"https://api.weather.gov/gridpoints/MKX/37,63/forecast\"\n", + "r = requests.get(url)\n", + "r.raise_for_status()\n", + "forecast_dict = None\n", + "\n", + "# did I get something? \n", + "forecast_dict\n", + "\n", + "# keys only please\n" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['updated', 'units', 'forecastGenerator', 'generatedAt', 'updateTime', 'validTimes', 'elevation', 'periods'])" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# go back to the web result...which key has the data I want? \n", + "forecast_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'number': 1,\n", + " 'name': 'Today',\n", + " 'startTime': '2022-11-16T08:00:00-06:00',\n", + " 'endTime': '2022-11-16T18:00:00-06:00',\n", + " 'isDaytime': True,\n", + " 'temperature': 34,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '5 to 10 mph',\n", + " 'windDirection': 'NW',\n", + " 'icon': 'https://api.weather.gov/icons/land/day/snow,60/snow,30?size=medium',\n", + " 'shortForecast': 'Snow Showers Likely',\n", + " 'detailedForecast': 'Snow showers likely. Cloudy, with a high near 34. Northwest wind 5 to 10 mph. Chance of precipitation is 60%. New snow accumulation of less than one inch possible.'},\n", + " {'number': 2,\n", + " 'name': 'Tonight',\n", + " 'startTime': '2022-11-16T18:00:00-06:00',\n", + " 'endTime': '2022-11-17T06:00:00-06:00',\n", + " 'isDaytime': False,\n", + " 'temperature': 23,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '5 to 10 mph',\n", + " 'windDirection': 'W',\n", + " 'icon': 'https://api.weather.gov/icons/land/night/snow?size=medium',\n", + " 'shortForecast': 'Chance Snow Showers',\n", + " 'detailedForecast': 'A chance of snow showers after 9pm. Mostly cloudy, with a low around 23. West wind 5 to 10 mph.'},\n", + " {'number': 3,\n", + " 'name': 'Thursday',\n", + " 'startTime': '2022-11-17T06:00:00-06:00',\n", + " 'endTime': '2022-11-17T18:00:00-06:00',\n", + " 'isDaytime': True,\n", + " 'temperature': 28,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '10 to 15 mph',\n", + " 'windDirection': 'W',\n", + " 'icon': 'https://api.weather.gov/icons/land/day/snow,30?size=medium',\n", + " 'shortForecast': 'Chance Snow Showers',\n", + " 'detailedForecast': 'A chance of snow showers. Mostly cloudy, with a high near 28. West wind 10 to 15 mph, with gusts as high as 25 mph. Chance of precipitation is 30%. New snow accumulation of less than half an inch possible.'},\n", + " {'number': 4,\n", + " 'name': 'Thursday Night',\n", + " 'startTime': '2022-11-17T18:00:00-06:00',\n", + " 'endTime': '2022-11-18T06:00:00-06:00',\n", + " 'isDaytime': False,\n", + " 'temperature': 17,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '15 mph',\n", + " 'windDirection': 'W',\n", + " 'icon': 'https://api.weather.gov/icons/land/night/bkn?size=medium',\n", + " 'shortForecast': 'Mostly Cloudy',\n", + " 'detailedForecast': 'Mostly cloudy, with a low around 17. West wind around 15 mph. New rainfall amounts less than a tenth of an inch possible.'},\n", + " {'number': 5,\n", + " 'name': 'Friday',\n", + " 'startTime': '2022-11-18T06:00:00-06:00',\n", + " 'endTime': '2022-11-18T18:00:00-06:00',\n", + " 'isDaytime': True,\n", + " 'temperature': 23,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '15 mph',\n", + " 'windDirection': 'W',\n", + " 'icon': 'https://api.weather.gov/icons/land/day/bkn?size=medium',\n", + " 'shortForecast': 'Mostly Cloudy',\n", + " 'detailedForecast': 'Mostly cloudy, with a high near 23. West wind around 15 mph.'},\n", + " {'number': 6,\n", + " 'name': 'Friday Night',\n", + " 'startTime': '2022-11-18T18:00:00-06:00',\n", + " 'endTime': '2022-11-19T06:00:00-06:00',\n", + " 'isDaytime': False,\n", + " 'temperature': 12,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '15 mph',\n", + " 'windDirection': 'SW',\n", + " 'icon': 'https://api.weather.gov/icons/land/night/bkn?size=medium',\n", + " 'shortForecast': 'Mostly Cloudy',\n", + " 'detailedForecast': 'Mostly cloudy, with a low around 12. Southwest wind around 15 mph.'},\n", + " {'number': 7,\n", + " 'name': 'Saturday',\n", + " 'startTime': '2022-11-19T06:00:00-06:00',\n", + " 'endTime': '2022-11-19T18:00:00-06:00',\n", + " 'isDaytime': True,\n", + " 'temperature': 23,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '15 mph',\n", + " 'windDirection': 'W',\n", + " 'icon': 'https://api.weather.gov/icons/land/day/bkn/snow,20?size=medium',\n", + " 'shortForecast': 'Mostly Cloudy then Slight Chance Snow Showers',\n", + " 'detailedForecast': 'A slight chance of snow showers after noon. Mostly cloudy, with a high near 23. West wind around 15 mph, with gusts as high as 25 mph. Chance of precipitation is 20%.'},\n", + " {'number': 8,\n", + " 'name': 'Saturday Night',\n", + " 'startTime': '2022-11-19T18:00:00-06:00',\n", + " 'endTime': '2022-11-20T06:00:00-06:00',\n", + " 'isDaytime': False,\n", + " 'temperature': 7,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '10 to 15 mph',\n", + " 'windDirection': 'W',\n", + " 'icon': 'https://api.weather.gov/icons/land/night/cold?size=medium',\n", + " 'shortForecast': 'Mostly Cloudy',\n", + " 'detailedForecast': 'Mostly cloudy, with a low around 7. West wind 10 to 15 mph, with gusts as high as 25 mph.'},\n", + " {'number': 9,\n", + " 'name': 'Sunday',\n", + " 'startTime': '2022-11-20T06:00:00-06:00',\n", + " 'endTime': '2022-11-20T18:00:00-06:00',\n", + " 'isDaytime': True,\n", + " 'temperature': 23,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '10 mph',\n", + " 'windDirection': 'W',\n", + " 'icon': 'https://api.weather.gov/icons/land/day/few?size=medium',\n", + " 'shortForecast': 'Sunny',\n", + " 'detailedForecast': 'Sunny, with a high near 23.'},\n", + " {'number': 10,\n", + " 'name': 'Sunday Night',\n", + " 'startTime': '2022-11-20T18:00:00-06:00',\n", + " 'endTime': '2022-11-21T06:00:00-06:00',\n", + " 'isDaytime': False,\n", + " 'temperature': 15,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': 'rising',\n", + " 'windSpeed': '10 mph',\n", + " 'windDirection': 'SW',\n", + " 'icon': 'https://api.weather.gov/icons/land/night/sct?size=medium',\n", + " 'shortForecast': 'Partly Cloudy',\n", + " 'detailedForecast': 'Partly cloudy. Low around 15, with temperatures rising to around 20 overnight.'},\n", + " {'number': 11,\n", + " 'name': 'Monday',\n", + " 'startTime': '2022-11-21T06:00:00-06:00',\n", + " 'endTime': '2022-11-21T18:00:00-06:00',\n", + " 'isDaytime': True,\n", + " 'temperature': 34,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': 'falling',\n", + " 'windSpeed': '5 to 10 mph',\n", + " 'windDirection': 'W',\n", + " 'icon': 'https://api.weather.gov/icons/land/day/few?size=medium',\n", + " 'shortForecast': 'Sunny',\n", + " 'detailedForecast': 'Sunny. High near 34, with temperatures falling to around 28 in the afternoon.'},\n", + " {'number': 12,\n", + " 'name': 'Monday Night',\n", + " 'startTime': '2022-11-21T18:00:00-06:00',\n", + " 'endTime': '2022-11-22T06:00:00-06:00',\n", + " 'isDaytime': False,\n", + " 'temperature': 18,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '5 mph',\n", + " 'windDirection': 'SW',\n", + " 'icon': 'https://api.weather.gov/icons/land/night/sct?size=medium',\n", + " 'shortForecast': 'Partly Cloudy',\n", + " 'detailedForecast': 'Partly cloudy, with a low around 18.'},\n", + " {'number': 13,\n", + " 'name': 'Tuesday',\n", + " 'startTime': '2022-11-22T06:00:00-06:00',\n", + " 'endTime': '2022-11-22T18:00:00-06:00',\n", + " 'isDaytime': True,\n", + " 'temperature': 36,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': 'falling',\n", + " 'windSpeed': '5 to 10 mph',\n", + " 'windDirection': 'SW',\n", + " 'icon': 'https://api.weather.gov/icons/land/day/sct?size=medium',\n", + " 'shortForecast': 'Mostly Sunny',\n", + " 'detailedForecast': 'Mostly sunny. High near 36, with temperatures falling to around 31 in the afternoon.'},\n", + " {'number': 14,\n", + " 'name': 'Tuesday Night',\n", + " 'startTime': '2022-11-22T18:00:00-06:00',\n", + " 'endTime': '2022-11-23T06:00:00-06:00',\n", + " 'isDaytime': False,\n", + " 'temperature': 26,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '5 mph',\n", + " 'windDirection': 'S',\n", + " 'icon': 'https://api.weather.gov/icons/land/night/bkn?size=medium',\n", + " 'shortForecast': 'Mostly Cloudy',\n", + " 'detailedForecast': 'Mostly cloudy, with a low around 26.'}]" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# use two key to get the value we want\n", + "forecast_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "list" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# what type is this? \n", + "forecast_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'number': 1,\n", + " 'name': 'Today',\n", + " 'startTime': '2022-11-16T08:00:00-06:00',\n", + " 'endTime': '2022-11-16T18:00:00-06:00',\n", + " 'isDaytime': True,\n", + " 'temperature': 34,\n", + " 'temperatureUnit': 'F',\n", + " 'temperatureTrend': None,\n", + " 'windSpeed': '5 to 10 mph',\n", + " 'windDirection': 'NW',\n", + " 'icon': 'https://api.weather.gov/icons/land/day/snow,60/snow,30?size=medium',\n", + " 'shortForecast': 'Snow Showers Likely',\n", + " 'detailedForecast': 'Snow showers likely. Cloudy, with a high near 34. Northwest wind 5 to 10 mph. Chance of precipitation is 60%. New snow accumulation of less than one inch possible.'}" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# what is the thing at index 0 in my list? \n", + "foreast_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "<div>\n", + "<style scoped>\n", + " .dataframe tbody tr th:only-of-type {\n", + " vertical-align: middle;\n", + " }\n", + "\n", + " .dataframe tbody tr th {\n", + " vertical-align: top;\n", + " }\n", + "\n", + " .dataframe thead th {\n", + " text-align: right;\n", + " }\n", + "</style>\n", + "<table border=\"1\" class=\"dataframe\">\n", + " <thead>\n", + " <tr style=\"text-align: right;\">\n", + " <th></th>\n", + " <th>number</th>\n", + " <th>name</th>\n", + " <th>startTime</th>\n", + " <th>endTime</th>\n", + " <th>isDaytime</th>\n", + " <th>temperature</th>\n", + " <th>temperatureUnit</th>\n", + " <th>temperatureTrend</th>\n", + " <th>windSpeed</th>\n", + " <th>windDirection</th>\n", + " <th>icon</th>\n", + " <th>shortForecast</th>\n", + " <th>detailedForecast</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>0</th>\n", + " <td>1</td>\n", + " <td>Today</td>\n", + " <td>2022-11-16T08:00:00-06:00</td>\n", + " <td>2022-11-16T18:00:00-06:00</td>\n", + " <td>True</td>\n", + " <td>34</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>5 to 10 mph</td>\n", + " <td>NW</td>\n", + " <td>https://api.weather.gov/icons/land/day/snow,60...</td>\n", + " <td>Snow Showers Likely</td>\n", + " <td>Snow showers likely. Cloudy, with a high near ...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1</th>\n", + " <td>2</td>\n", + " <td>Tonight</td>\n", + " <td>2022-11-16T18:00:00-06:00</td>\n", + " <td>2022-11-17T06:00:00-06:00</td>\n", + " <td>False</td>\n", + " <td>23</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>5 to 10 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/night/snow?...</td>\n", + " <td>Chance Snow Showers</td>\n", + " <td>A chance of snow showers after 9pm. Mostly clo...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>2</th>\n", + " <td>3</td>\n", + " <td>Thursday</td>\n", + " <td>2022-11-17T06:00:00-06:00</td>\n", + " <td>2022-11-17T18:00:00-06:00</td>\n", + " <td>True</td>\n", + " <td>28</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>10 to 15 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/day/snow,30...</td>\n", + " <td>Chance Snow Showers</td>\n", + " <td>A chance of snow showers. Mostly cloudy, with ...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>3</th>\n", + " <td>4</td>\n", + " <td>Thursday Night</td>\n", + " <td>2022-11-17T18:00:00-06:00</td>\n", + " <td>2022-11-18T06:00:00-06:00</td>\n", + " <td>False</td>\n", + " <td>17</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>15 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/night/bkn?s...</td>\n", + " <td>Mostly Cloudy</td>\n", + " <td>Mostly cloudy, with a low around 17. West wind...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>4</th>\n", + " <td>5</td>\n", + " <td>Friday</td>\n", + " <td>2022-11-18T06:00:00-06:00</td>\n", + " <td>2022-11-18T18:00:00-06:00</td>\n", + " <td>True</td>\n", + " <td>23</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>15 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/day/bkn?siz...</td>\n", + " <td>Mostly Cloudy</td>\n", + " <td>Mostly cloudy, with a high near 23. West wind ...</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "</div>" + ], + "text/plain": [ + " number name startTime \\\n", + "0 1 Today 2022-11-16T08:00:00-06:00 \n", + "1 2 Tonight 2022-11-16T18:00:00-06:00 \n", + "2 3 Thursday 2022-11-17T06:00:00-06:00 \n", + "3 4 Thursday Night 2022-11-17T18:00:00-06:00 \n", + "4 5 Friday 2022-11-18T06:00:00-06:00 \n", + "\n", + " endTime isDaytime temperature temperatureUnit \\\n", + "0 2022-11-16T18:00:00-06:00 True 34 F \n", + "1 2022-11-17T06:00:00-06:00 False 23 F \n", + "2 2022-11-17T18:00:00-06:00 True 28 F \n", + "3 2022-11-18T06:00:00-06:00 False 17 F \n", + "4 2022-11-18T18:00:00-06:00 True 23 F \n", + "\n", + " temperatureTrend windSpeed windDirection \\\n", + "0 None 5 to 10 mph NW \n", + "1 None 5 to 10 mph W \n", + "2 None 10 to 15 mph W \n", + "3 None 15 mph W \n", + "4 None 15 mph W \n", + "\n", + " icon shortForecast \\\n", + "0 https://api.weather.gov/icons/land/day/snow,60... Snow Showers Likely \n", + "1 https://api.weather.gov/icons/land/night/snow?... Chance Snow Showers \n", + "2 https://api.weather.gov/icons/land/day/snow,30... Chance Snow Showers \n", + "3 https://api.weather.gov/icons/land/night/bkn?s... Mostly Cloudy \n", + "4 https://api.weather.gov/icons/land/day/bkn?siz... Mostly Cloudy \n", + "\n", + " detailedForecast \n", + "0 Snow showers likely. Cloudy, with a high near ... \n", + "1 A chance of snow showers after 9pm. Mostly clo... \n", + "2 A chance of snow showers. Mostly cloudy, with ... \n", + "3 Mostly cloudy, with a low around 17. West wind... \n", + "4 Mostly cloudy, with a high near 23. West wind ... " + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# OK, so this is a list of dicts\n", + "# can I read it into a Pandas DataFrame?\n", + "\n", + "forecast_df = ...\n", + "forecast_df" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "# I don't like that index in there twice, let's get rid of the index\n" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "<div>\n", + "<style scoped>\n", + " .dataframe tbody tr th:only-of-type {\n", + " vertical-align: middle;\n", + " }\n", + "\n", + " .dataframe tbody tr th {\n", + " vertical-align: top;\n", + " }\n", + "\n", + " .dataframe thead th {\n", + " text-align: right;\n", + " }\n", + "</style>\n", + "<table border=\"1\" class=\"dataframe\">\n", + " <thead>\n", + " <tr style=\"text-align: right;\">\n", + " <th></th>\n", + " <th>name</th>\n", + " <th>startTime</th>\n", + " <th>endTime</th>\n", + " <th>isDaytime</th>\n", + " <th>temperature</th>\n", + " <th>temperatureUnit</th>\n", + " <th>temperatureTrend</th>\n", + " <th>windSpeed</th>\n", + " <th>windDirection</th>\n", + " <th>icon</th>\n", + " <th>shortForecast</th>\n", + " <th>detailedForecast</th>\n", + " </tr>\n", + " <tr>\n", + " <th>number</th>\n", + " <th></th>\n", + " <th></th>\n", + " <th></th>\n", + " <th></th>\n", + " <th></th>\n", + " <th></th>\n", + " <th></th>\n", + " <th></th>\n", + " <th></th>\n", + " <th></th>\n", + " <th></th>\n", + " <th></th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>1</th>\n", + " <td>Today</td>\n", + " <td>2022-11-16T08:00:00-06:00</td>\n", + " <td>2022-11-16T18:00:00-06:00</td>\n", + " <td>True</td>\n", + " <td>34</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>5 to 10 mph</td>\n", + " <td>NW</td>\n", + " <td>https://api.weather.gov/icons/land/day/snow,60...</td>\n", + " <td>Snow Showers Likely</td>\n", + " <td>Snow showers likely. Cloudy, with a high near ...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>2</th>\n", + " <td>Tonight</td>\n", + " <td>2022-11-16T18:00:00-06:00</td>\n", + " <td>2022-11-17T06:00:00-06:00</td>\n", + " <td>False</td>\n", + " <td>23</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>5 to 10 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/night/snow?...</td>\n", + " <td>Chance Snow Showers</td>\n", + " <td>A chance of snow showers after 9pm. Mostly clo...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>3</th>\n", + " <td>Thursday</td>\n", + " <td>2022-11-17T06:00:00-06:00</td>\n", + " <td>2022-11-17T18:00:00-06:00</td>\n", + " <td>True</td>\n", + " <td>28</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>10 to 15 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/day/snow,30...</td>\n", + " <td>Chance Snow Showers</td>\n", + " <td>A chance of snow showers. Mostly cloudy, with ...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>4</th>\n", + " <td>Thursday Night</td>\n", + " <td>2022-11-17T18:00:00-06:00</td>\n", + " <td>2022-11-18T06:00:00-06:00</td>\n", + " <td>False</td>\n", + " <td>17</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>15 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/night/bkn?s...</td>\n", + " <td>Mostly Cloudy</td>\n", + " <td>Mostly cloudy, with a low around 17. West wind...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>5</th>\n", + " <td>Friday</td>\n", + " <td>2022-11-18T06:00:00-06:00</td>\n", + " <td>2022-11-18T18:00:00-06:00</td>\n", + " <td>True</td>\n", + " <td>23</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>15 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/day/bkn?siz...</td>\n", + " <td>Mostly Cloudy</td>\n", + " <td>Mostly cloudy, with a high near 23. West wind ...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>6</th>\n", + " <td>Friday Night</td>\n", + " <td>2022-11-18T18:00:00-06:00</td>\n", + " <td>2022-11-19T06:00:00-06:00</td>\n", + " <td>False</td>\n", + " <td>12</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>15 mph</td>\n", + " <td>SW</td>\n", + " <td>https://api.weather.gov/icons/land/night/bkn?s...</td>\n", + " <td>Mostly Cloudy</td>\n", + " <td>Mostly cloudy, with a low around 12. Southwest...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7</th>\n", + " <td>Saturday</td>\n", + " <td>2022-11-19T06:00:00-06:00</td>\n", + " <td>2022-11-19T18:00:00-06:00</td>\n", + " <td>True</td>\n", + " <td>23</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>15 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/day/bkn/sno...</td>\n", + " <td>Mostly Cloudy then Slight Chance Snow Showers</td>\n", + " <td>A slight chance of snow showers after noon. Mo...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>8</th>\n", + " <td>Saturday Night</td>\n", + " <td>2022-11-19T18:00:00-06:00</td>\n", + " <td>2022-11-20T06:00:00-06:00</td>\n", + " <td>False</td>\n", + " <td>7</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>10 to 15 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/night/cold?...</td>\n", + " <td>Mostly Cloudy</td>\n", + " <td>Mostly cloudy, with a low around 7. West wind ...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>9</th>\n", + " <td>Sunday</td>\n", + " <td>2022-11-20T06:00:00-06:00</td>\n", + " <td>2022-11-20T18:00:00-06:00</td>\n", + " <td>True</td>\n", + " <td>23</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>10 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/day/few?siz...</td>\n", + " <td>Sunny</td>\n", + " <td>Sunny, with a high near 23.</td>\n", + " </tr>\n", + " <tr>\n", + " <th>10</th>\n", + " <td>Sunday Night</td>\n", + " <td>2022-11-20T18:00:00-06:00</td>\n", + " <td>2022-11-21T06:00:00-06:00</td>\n", + " <td>False</td>\n", + " <td>15</td>\n", + " <td>F</td>\n", + " <td>rising</td>\n", + " <td>10 mph</td>\n", + " <td>SW</td>\n", + " <td>https://api.weather.gov/icons/land/night/sct?s...</td>\n", + " <td>Partly Cloudy</td>\n", + " <td>Partly cloudy. Low around 15, with temperature...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>11</th>\n", + " <td>Monday</td>\n", + " <td>2022-11-21T06:00:00-06:00</td>\n", + " <td>2022-11-21T18:00:00-06:00</td>\n", + " <td>True</td>\n", + " <td>34</td>\n", + " <td>F</td>\n", + " <td>falling</td>\n", + " <td>5 to 10 mph</td>\n", + " <td>W</td>\n", + " <td>https://api.weather.gov/icons/land/day/few?siz...</td>\n", + " <td>Sunny</td>\n", + " <td>Sunny. High near 34, with temperatures falling...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>12</th>\n", + " <td>Monday Night</td>\n", + " <td>2022-11-21T18:00:00-06:00</td>\n", + " <td>2022-11-22T06:00:00-06:00</td>\n", + " <td>False</td>\n", + " <td>18</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>5 mph</td>\n", + " <td>SW</td>\n", + " <td>https://api.weather.gov/icons/land/night/sct?s...</td>\n", + " <td>Partly Cloudy</td>\n", + " <td>Partly cloudy, with a low around 18.</td>\n", + " </tr>\n", + " <tr>\n", + " <th>13</th>\n", + " <td>Tuesday</td>\n", + " <td>2022-11-22T06:00:00-06:00</td>\n", + " <td>2022-11-22T18:00:00-06:00</td>\n", + " <td>True</td>\n", + " <td>36</td>\n", + " <td>F</td>\n", + " <td>falling</td>\n", + " <td>5 to 10 mph</td>\n", + " <td>SW</td>\n", + " <td>https://api.weather.gov/icons/land/day/sct?siz...</td>\n", + " <td>Mostly Sunny</td>\n", + " <td>Mostly sunny. High near 36, with temperatures ...</td>\n", + " </tr>\n", + " <tr>\n", + " <th>14</th>\n", + " <td>Tuesday Night</td>\n", + " <td>2022-11-22T18:00:00-06:00</td>\n", + " <td>2022-11-23T06:00:00-06:00</td>\n", + " <td>False</td>\n", + " <td>26</td>\n", + " <td>F</td>\n", + " <td>None</td>\n", + " <td>5 mph</td>\n", + " <td>S</td>\n", + " <td>https://api.weather.gov/icons/land/night/bkn?s...</td>\n", + " <td>Mostly Cloudy</td>\n", + " <td>Mostly cloudy, with a low around 26.</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "</div>" + ], + "text/plain": [ + " name startTime endTime \\\n", + "number \n", + "1 Today 2022-11-16T08:00:00-06:00 2022-11-16T18:00:00-06:00 \n", + "2 Tonight 2022-11-16T18:00:00-06:00 2022-11-17T06:00:00-06:00 \n", + "3 Thursday 2022-11-17T06:00:00-06:00 2022-11-17T18:00:00-06:00 \n", + "4 Thursday Night 2022-11-17T18:00:00-06:00 2022-11-18T06:00:00-06:00 \n", + "5 Friday 2022-11-18T06:00:00-06:00 2022-11-18T18:00:00-06:00 \n", + "6 Friday Night 2022-11-18T18:00:00-06:00 2022-11-19T06:00:00-06:00 \n", + "7 Saturday 2022-11-19T06:00:00-06:00 2022-11-19T18:00:00-06:00 \n", + "8 Saturday Night 2022-11-19T18:00:00-06:00 2022-11-20T06:00:00-06:00 \n", + "9 Sunday 2022-11-20T06:00:00-06:00 2022-11-20T18:00:00-06:00 \n", + "10 Sunday Night 2022-11-20T18:00:00-06:00 2022-11-21T06:00:00-06:00 \n", + "11 Monday 2022-11-21T06:00:00-06:00 2022-11-21T18:00:00-06:00 \n", + "12 Monday Night 2022-11-21T18:00:00-06:00 2022-11-22T06:00:00-06:00 \n", + "13 Tuesday 2022-11-22T06:00:00-06:00 2022-11-22T18:00:00-06:00 \n", + "14 Tuesday Night 2022-11-22T18:00:00-06:00 2022-11-23T06:00:00-06:00 \n", + "\n", + " isDaytime temperature temperatureUnit temperatureTrend windSpeed \\\n", + "number \n", + "1 True 34 F None 5 to 10 mph \n", + "2 False 23 F None 5 to 10 mph \n", + "3 True 28 F None 10 to 15 mph \n", + "4 False 17 F None 15 mph \n", + "5 True 23 F None 15 mph \n", + "6 False 12 F None 15 mph \n", + "7 True 23 F None 15 mph \n", + "8 False 7 F None 10 to 15 mph \n", + "9 True 23 F None 10 mph \n", + "10 False 15 F rising 10 mph \n", + "11 True 34 F falling 5 to 10 mph \n", + "12 False 18 F None 5 mph \n", + "13 True 36 F falling 5 to 10 mph \n", + "14 False 26 F None 5 mph \n", + "\n", + " windDirection icon \\\n", + "number \n", + "1 NW https://api.weather.gov/icons/land/day/snow,60... \n", + "2 W https://api.weather.gov/icons/land/night/snow?... \n", + "3 W https://api.weather.gov/icons/land/day/snow,30... \n", + "4 W https://api.weather.gov/icons/land/night/bkn?s... \n", + "5 W https://api.weather.gov/icons/land/day/bkn?siz... \n", + "6 SW https://api.weather.gov/icons/land/night/bkn?s... \n", + "7 W https://api.weather.gov/icons/land/day/bkn/sno... \n", + "8 W https://api.weather.gov/icons/land/night/cold?... \n", + "9 W https://api.weather.gov/icons/land/day/few?siz... \n", + "10 SW https://api.weather.gov/icons/land/night/sct?s... \n", + "11 W https://api.weather.gov/icons/land/day/few?siz... \n", + "12 SW https://api.weather.gov/icons/land/night/sct?s... \n", + "13 SW https://api.weather.gov/icons/land/day/sct?siz... \n", + "14 S https://api.weather.gov/icons/land/night/bkn?s... \n", + "\n", + " shortForecast \\\n", + "number \n", + "1 Snow Showers Likely \n", + "2 Chance Snow Showers \n", + "3 Chance Snow Showers \n", + "4 Mostly Cloudy \n", + "5 Mostly Cloudy \n", + "6 Mostly Cloudy \n", + "7 Mostly Cloudy then Slight Chance Snow Showers \n", + "8 Mostly Cloudy \n", + "9 Sunny \n", + "10 Partly Cloudy \n", + "11 Sunny \n", + "12 Partly Cloudy \n", + "13 Mostly Sunny \n", + "14 Mostly Cloudy \n", + "\n", + " detailedForecast \n", + "number \n", + "1 Snow showers likely. Cloudy, with a high near ... \n", + "2 A chance of snow showers after 9pm. Mostly clo... \n", + "3 A chance of snow showers. Mostly cloudy, with ... \n", + "4 Mostly cloudy, with a low around 17. West wind... \n", + "5 Mostly cloudy, with a high near 23. West wind ... \n", + "6 Mostly cloudy, with a low around 12. Southwest... \n", + "7 A slight chance of snow showers after noon. Mo... \n", + "8 Mostly cloudy, with a low around 7. West wind ... \n", + "9 Sunny, with a high near 23. \n", + "10 Partly cloudy. Low around 15, with temperature... \n", + "11 Sunny. High near 34, with temperatures falling... \n", + "12 Partly cloudy, with a low around 18. \n", + "13 Mostly sunny. High near 36, with temperatures ... \n", + "14 Mostly cloudy, with a low around 26. " + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# how do you set 'number' to be the index ? \n", + "# let's do a Google Search\n", + "forecast_df = ...\n", + "forecast_df" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# what is the coldest forecasted temp? \n", + "forecast_df" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Sunny. High near 34, with temperatures falling to around 28 in the afternoon.'" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# what is the detailed forecast for Monday?\n", + "forecast_df" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "# what else can we find out? " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# how do I get the National Weather Service forecast for any city? \n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.12" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}