Assignment 4

Before working on this assignment please read these instructions fully. In the submission area, you will notice that you can click the link to Preview the Grading for each step of the assignment. This is the criteria that will be used for peer grading. Please familiarize yourself with the criteria before beginning the assignment.

This assignment requires that you to find at least two datasets on the web which are related, and that you visualize these datasets to answer a question with the broad topic of sports or athletics (see below) for the region of Ann Arbor, Michigan, United States, or United States more broadly.

You can merge these datasets with data from different regions if you like! For instance, you might want to compare Ann Arbor, Michigan, United States to Ann Arbor, USA. In that case at least one source file must be about Ann Arbor, Michigan, United States.

You are welcome to choose datasets at your discretion, but keep in mind they will be shared with your peers, so choose appropriate datasets. Sensitive, confidential, illicit, and proprietary materials are not good choices for datasets for this assignment. You are welcome to upload datasets of your own as well, and link to them using a third party repository such as github, bitbucket, pastebin, etc. Please be aware of the Coursera terms of service with respect to intellectual property.

Also, you are welcome to preserve data in its original language, but for the purposes of grading you should provide english translations. You are welcome to provide multiple visuals in different languages if you would like!

As this assignment is for the whole course, you must incorporate principles discussed in the first week, such as having as high data-ink ratio (Tufte) and aligning with Cairo’s principles of truth, beauty, function, and insight.

Here are the assignment instructions:

  • State the region and the domain category that your data sets are about (e.g., Ann Arbor, Michigan, United States and sports or athletics).
  • You must state a question about the domain category and region that you identified as being interesting.
  • You must provide at least two links to available datasets. These could be links to files such as CSV or Excel files, or links to websites which might have data in tabular form, such as Wikipedia pages.
  • You must upload an image which addresses the research question you stated. In addition to addressing the question, this visual should follow Cairo's principles of truthfulness, functionality, beauty, and insightfulness.
  • You must contribute a short (1-2 paragraph) written justification of how your visualization addresses your stated research question.

What do we mean by sports or athletics? For this category we are interested in sporting events or athletics broadly, please feel free to creatively interpret the category when building your research question!

Tips

  • Wikipedia is an excellent source of data, and I strongly encourage you to explore it for new data sources.
  • Many governments run open data initiatives at the city, region, and country levels, and these are wonderful resources for localized data sources.
  • Several international agencies, such as the United Nations, the World Bank, the Global Open Data Index are other great places to look for data.
  • This assignment requires you to convert and clean datafiles. Check out the discussion forums for tips on how to do this from various sources, and share your successes with your fellow students!

Example

Looking for an example? Here's what our course assistant put together for the Ann Arbor, MI, USA area using sports and athletics as the topic. Example Solution File


In [1]:
!conda install html5lib -y
!conda install beautifulsoup4 -y
!conda install lxml -y
!conda install urllib2 -y


Fetching package metadata .........
Solving package specifications: ..........

# All requested packages already installed.
# packages in environment at /opt/conda:
#
html5lib                  0.999999999              py35_0    conda-forge
Fetching package metadata .........
Solving package specifications: ..........

# All requested packages already installed.
# packages in environment at /opt/conda:
#
beautifulsoup4            4.5.3                    py35_0    conda-forge
Fetching package metadata .........
Solving package specifications: ..........

# All requested packages already installed.
# packages in environment at /opt/conda:
#
lxml                      3.7.3                    py35_0    conda-forge
Fetching package metadata .........
Solving package specifications: .
Error: Package missing in current linux-64 channels: 
  - urllib2

Close matches found; did you mean one of these?

    urllib2: urllib3

You can search for packages on anaconda.org with

    anaconda search -t conda urllib2

You may need to install the anaconda-client command line client with

    conda install anaconda-client

Note that you have pinned specs in /opt/conda/conda-meta/pinned:

    ['jpeg 8*']

In [2]:
import urllib
import urllib.request
from bs4 import BeautifulSoup
import pandas as pd

soup =BeautifulSoup(urllib.request.urlopen('https://en.wikipedia.org/wiki/2008_Detroit_Lions_season').read())
table = soup.find_all("table", { "class" : "wikitable" })[2]
print(table)


/opt/conda/lib/python3.5/site-packages/bs4/__init__.py:181: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html5lib"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 184 of the file /opt/conda/lib/python3.5/runpy.py. To get rid of this warning, change code that looks like this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "html5lib")

  markup_type=markup_type))
<table align="center" class="wikitable" style="font-size: 100%;">
<tbody><tr>
<th rowspan="2">Week</th>
<th rowspan="2">Date</th>
<th rowspan="2">Kickoff</th>
<th rowspan="2">Opponent</th>
<th colspan="2">Results</th>
<th rowspan="2">Game Site</th>
<th rowspan="2">TV</th>
<th rowspan="2">NFL Recap</th>
</tr>
<tr>
<th>Final score</th>
<th>Team record</th>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">1</th>
<td align="center" style="background: #ffdddd;">September 7, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM <a class="mw-redirect" href="/wiki/North_American_Eastern_Time_Zone" title="North American Eastern Time Zone">EDT</a></td>
<td align="center" style="background: #ffdddd;">at <a href="/wiki/2008_Atlanta_Falcons_season" title="2008 Atlanta Falcons season">Atlanta Falcons</a></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 21–34</td>
<td align="center" style="background: #ffdddd;">0–1</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/Georgia_Dome" title="Georgia Dome">Georgia Dome</a></td>
<td align="center" style="background: #ffdddd;"><a class="mw-redirect" href="/wiki/NFL_on_Fox" title="NFL on Fox">FOX</a></td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29529&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG1" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">2</th>
<td align="center" style="background: #ffdddd;">September 14, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EDT</td>
<td align="center" style="background: #ffdddd;"><b><a href="/wiki/2008_Green_Bay_Packers_season" title="2008 Green Bay Packers season">Green Bay Packers</a></b></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 25–48</td>
<td align="center" style="background: #ffdddd;">0–2</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/Ford_Field" title="Ford Field">Ford Field</a></td>
<td align="center" style="background: #ffdddd;">FOX</td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29546&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG2" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">3</th>
<td align="center" style="background: #ffdddd;">September 21, 2008</td>
<td align="center" style="background: #ffdddd;">4:05 PM EDT</td>
<td align="center" style="background: #ffdddd;">at <a href="/wiki/2008_San_Francisco_49ers_season" title="2008 San Francisco 49ers season">San Francisco 49ers</a></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 13–31</td>
<td align="center" style="background: #ffdddd;">0–3</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/Candlestick_Park" title="Candlestick Park">Candlestick Park</a></td>
<td align="center" style="background: #ffdddd;">FOX</td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29569&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG3" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center">4</th>
<td align="center" colspan="8" valign="middle"><i><a href="/wiki/Bye_(sports)" title="Bye (sports)">Bye</a></i></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">5</th>
<td align="center" style="background: #ffdddd;">October 5, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EDT</td>
<td align="center" style="background: #ffdddd;"><b><a href="/wiki/2008_Chicago_Bears_season" title="2008 Chicago Bears season">Chicago Bears</a></b></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 7–34</td>
<td align="center" style="background: #ffdddd;">0–4</td>
<td align="center" style="background: #ffdddd;">Ford Field</td>
<td align="center" style="background: #ffdddd;">FOX</td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29591&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG5" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">6</th>
<td align="center" style="background: #ffdddd;">October 12, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EDT</td>
<td align="center" style="background: #ffdddd;">at <b><a href="/wiki/2008_Minnesota_Vikings_season" title="2008 Minnesota Vikings season">Minnesota Vikings</a></b></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 10–12</td>
<td align="center" style="background: #ffdddd;">0–5</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/Hubert_H._Humphrey_Metrodome" title="Hubert H. Humphrey Metrodome">Hubert H. Humphrey Metrodome</a></td>
<td align="center" style="background: #ffdddd;">FOX</td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29606&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG6" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">7</th>
<td align="center" style="background: #ffdddd;">October 19, 2008</td>
<td align="center" style="background: #ffdddd;">4:05 PM EDT</td>
<td align="center" style="background: #ffdddd;">at <a href="/wiki/2008_Houston_Texans_season" title="2008 Houston Texans season">Houston Texans</a></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 21–28</td>
<td align="center" style="background: #ffdddd;">0–6</td>
<td align="center" style="background: #ffdddd;"><a class="mw-redirect" href="/wiki/Reliant_Stadium" title="Reliant Stadium">Reliant Stadium</a></td>
<td align="center" style="background: #ffdddd;">FOX</td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29625&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG7" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">8</th>
<td align="center" style="background: #ffdddd;">October 26, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EDT</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/2008_Washington_Redskins_season" title="2008 Washington Redskins season">Washington Redskins</a></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 17–25</td>
<td align="center" style="background: #ffdddd;">0–7</td>
<td align="center" style="background: #ffdddd;">Ford Field</td>
<td align="center" style="background: #ffdddd;">FOX <small>x</small></td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29634&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG8" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">9</th>
<td align="center" style="background: #ffdddd;">November 2, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM <a class="mw-redirect" href="/wiki/North_American_Eastern_Time_Zone" title="North American Eastern Time Zone">EST</a></td>
<td align="center" style="background: #ffdddd;">at <b>Chicago Bears</b></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 23–27</td>
<td align="center" style="background: #ffdddd;">0–8</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/Soldier_Field" title="Soldier Field">Soldier Field</a></td>
<td align="center" style="background: #ffdddd;">FOX</td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29645&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG9" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">10</th>
<td align="center" style="background: #ffdddd;">November 9, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EST</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/2008_Jacksonville_Jaguars_season" title="2008 Jacksonville Jaguars season">Jacksonville Jaguars</a></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 14–38</td>
<td align="center" style="background: #ffdddd;">0–9</td>
<td align="center" style="background: #ffdddd;">Ford Field</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/NFL_on_CBS" title="NFL on CBS">CBS</a> <small>x</small></td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29661&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG10" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">11</th>
<td align="center" style="background: #ffdddd;">November 16, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EST</td>
<td align="center" style="background: #ffdddd;">at <a href="/wiki/2008_Carolina_Panthers_season" title="2008 Carolina Panthers season">Carolina Panthers</a></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 22–31</td>
<td align="center" style="background: #ffdddd;">0–10</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/Bank_of_America_Stadium" title="Bank of America Stadium">Bank of America Stadium</a></td>
<td align="center" style="background: #ffdddd;">FOX</td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29674&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG11" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">12</th>
<td align="center" style="background: #ffdddd;">November 23, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EST</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/2008_Tampa_Bay_Buccaneers_season" title="2008 Tampa Bay Buccaneers season">Tampa Bay Buccaneers</a></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 20–38</td>
<td align="center" style="background: #ffdddd;">0–11</td>
<td align="center" style="background: #ffdddd;">Ford Field</td>
<td align="center" style="background: #ffdddd;">FOX <small>x</small></td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29693&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG12" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">13</th>
<td align="center" style="background: #ffdddd;"><a href="/wiki/NFL_on_Thanksgiving_Day" title="NFL on Thanksgiving Day">November 27, 2008</a></td>
<td align="center" style="background: #ffdddd;">12:30 PM EST</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/2008_Tennessee_Titans_season" title="2008 Tennessee Titans season">Tennessee Titans</a></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 10–47</td>
<td align="center" style="background: #ffdddd;">0–12</td>
<td align="center" style="background: #ffdddd;">Ford Field</td>
<td align="center" style="background: #ffdddd;">CBS #</td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter?game_id=29704&amp;season=2008&amp;displayPage=tab_gamecenter&amp;week=REG13" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">14</th>
<td align="center" style="background: #ffdddd;">December 7, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EST</td>
<td align="center" style="background: #ffdddd;"><b>Minnesota Vikings</b></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 16–20</td>
<td align="center" style="background: #ffdddd;">0–13</td>
<td align="center" style="background: #ffdddd;">Ford Field</td>
<td align="center" style="background: #ffdddd;">FOX <small>x</small></td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter/recap?game_id=29723&amp;displayPage=tab_recap&amp;season=2008&amp;week=REG14&amp;override=true" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">15</th>
<td align="center" style="background: #ffdddd;">December 14, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EST</td>
<td align="center" style="background: #ffdddd;">at <a href="/wiki/2008_Indianapolis_Colts_season" title="2008 Indianapolis Colts season">Indianapolis Colts</a></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 21–31</td>
<td align="center" style="background: #ffdddd;">0–14</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/Lucas_Oil_Stadium" title="Lucas Oil Stadium">Lucas Oil Stadium</a></td>
<td align="center" style="background: #ffdddd;">FOX</td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter/recap?game_id=29742&amp;displayPage=tab_recap&amp;season=2008&amp;week=REG15&amp;override=true" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">16</th>
<td align="center" style="background: #ffdddd;">December 21, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EST</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/2008_New_Orleans_Saints_season" title="2008 New Orleans Saints season">New Orleans Saints</a></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 7–42</td>
<td align="center" style="background: #ffdddd;">0–15</td>
<td align="center" style="background: #ffdddd;">Ford Field</td>
<td align="center" style="background: #ffdddd;">FOX <small>x</small></td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://www.nfl.com/gamecenter/recap?game_id=29755&amp;displayPage=tab_recap&amp;season=2008&amp;week=REG16&amp;override=true" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center" style="background: #ffdddd;">17</th>
<td align="center" style="background: #ffdddd;">December 28, 2008</td>
<td align="center" style="background: #ffdddd;">1:00 PM EST</td>
<td align="center" style="background: #ffdddd;">at <b>Green Bay Packers</b></td>
<td align="center" style="background: #ffdddd;"><b>L</b> 21–31</td>
<td align="center" style="background: #ffdddd;">0–16</td>
<td align="center" style="background: #ffdddd;"><a href="/wiki/Lambeau_Field" title="Lambeau Field">Lambeau Field</a></td>
<td align="center" style="background: #ffdddd;">FOX</td>
<td align="center" style="background: #ffdddd;"><a class="external text" href="http://sports.espn.go.com/nfl/recap?gameId=281228009" rel="nofollow">Recap</a></td>
</tr>
</tbody></table>

In [3]:
n_columns = 0
n_rows=0
column_names = []
# Find number of rows and columns
# we also find the column titles if we can
for row in table.find_all('tr'):
    # Determine the number of rows in the table
    td_tags = row.find_all('td')
    if len(td_tags) > 0:
        n_rows+=1
        if n_columns == 0:
            # Set the number of columns for our table
            n_columns = len(td_tags)
                        
    # Handle column names if we find them
    th_tags = row.find_all('th') 
    if len(th_tags) > 0 and len(column_names) == 0:
        for th in th_tags:
            column_names.append(th.get_text())
                    
# Safeguard on Column Titles
if len(column_names) > 0 and len(column_names) != n_columns:
    raise Exception("Column titles do not match the number of columns")
    
columns = column_names if len(column_names) > 0 else range(0,n_columns)
lions08df = pd.DataFrame(columns = columns, index= range(0,n_rows))
row_marker = 0
for row in table.find_all('tr'):
    column_marker = 0
    columns = row.find_all('td')
    for column in columns:
        lions08df.iat[row_marker,column_marker] = column.get_text()
        column_marker += 1
    if len(columns) > 0:
        row_marker += 1

In [4]:
lions08df


Out[4]:
Week Date Kickoff Opponent Results Game Site TV NFL Recap
0 September 7, 2008 1:00 PM EDT at Atlanta Falcons L 21–34 0–1 Georgia Dome FOX Recap
1 September 14, 2008 1:00 PM EDT Green Bay Packers L 25–48 0–2 Ford Field FOX Recap
2 September 21, 2008 4:05 PM EDT at San Francisco 49ers L 13–31 0–3 Candlestick Park FOX Recap
3 Bye NaN NaN NaN NaN NaN NaN NaN
4 October 5, 2008 1:00 PM EDT Chicago Bears L 7–34 0–4 Ford Field FOX Recap
5 October 12, 2008 1:00 PM EDT at Minnesota Vikings L 10–12 0–5 Hubert H. Humphrey Metrodome FOX Recap
6 October 19, 2008 4:05 PM EDT at Houston Texans L 21–28 0–6 Reliant Stadium FOX Recap
7 October 26, 2008 1:00 PM EDT Washington Redskins L 17–25 0–7 Ford Field FOX x Recap
8 November 2, 2008 1:00 PM EST at Chicago Bears L 23–27 0–8 Soldier Field FOX Recap
9 November 9, 2008 1:00 PM EST Jacksonville Jaguars L 14–38 0–9 Ford Field CBS x Recap
10 November 16, 2008 1:00 PM EST at Carolina Panthers L 22–31 0–10 Bank of America Stadium FOX Recap
11 November 23, 2008 1:00 PM EST Tampa Bay Buccaneers L 20–38 0–11 Ford Field FOX x Recap
12 November 27, 2008 12:30 PM EST Tennessee Titans L 10–47 0–12 Ford Field CBS # Recap
13 December 7, 2008 1:00 PM EST Minnesota Vikings L 16–20 0–13 Ford Field FOX x Recap
14 December 14, 2008 1:00 PM EST at Indianapolis Colts L 21–31 0–14 Lucas Oil Stadium FOX Recap
15 December 21, 2008 1:00 PM EST New Orleans Saints L 7–42 0–15 Ford Field FOX x Recap
16 December 28, 2008 1:00 PM EST at Green Bay Packers L 21–31 0–16 Lambeau Field FOX Recap

In [5]:
soup =BeautifulSoup(urllib.request.urlopen('https://en.wikipedia.org/wiki/2009_St._Louis_Rams_season').read())
table = soup.find_all("table", { "class" : "wikitable" })[1]
print(table)


/opt/conda/lib/python3.5/site-packages/bs4/__init__.py:181: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html5lib"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 184 of the file /opt/conda/lib/python3.5/runpy.py. To get rid of this warning, change code that looks like this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "html5lib")

  markup_type=markup_type))
<table align="center" class="wikitable" style="font-size: 95%;">
<tbody><tr>
<th rowspan="2">Week</th>
<th rowspan="2">Date</th>
<th rowspan="2">Kickoff (<a class="mw-redirect" href="/wiki/Central_Time_Zone_(Americas)" title="Central Time Zone (Americas)">CT</a>)</th>
<th rowspan="2">Opponent</th>
<th colspan="2">Results</th>
<th rowspan="2">Game Site</th>
<th rowspan="2">TV</th>
<th rowspan="2">NFL Recap</th>
</tr>
<tr>
<th>Final score</th>
<th>Team record</th>
</tr>
<tr style="background: #ffdddd;">
<th align="center">1</th>
<td align="center">September 13</td>
<td align="center">3:15 PM</td>
<td align="center">at <b><a href="/wiki/2009_Seattle_Seahawks_season" title="2009 Seattle Seahawks season">Seattle Seahawks</a></b></td>
<td align="center"><b>L</b> 0–28</td>
<td align="center">0–1</td>
<td align="center"><a class="mw-redirect" href="/wiki/Qwest_Field" title="Qwest Field">Qwest Field</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009091311/2009/REG1/rams@seahawks" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">2</th>
<td align="center">September 20</td>
<td align="center">12:00 PM</td>
<td align="center">at <a href="/wiki/2009_Washington_Redskins_season" title="2009 Washington Redskins season">Washington Redskins</a></td>
<td align="center"><b>L</b> 7–9</td>
<td align="center">0–2</td>
<td align="center"><a href="/wiki/FedExField" title="FedExField">FedExField</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009092008/2009/REG2/rams@redskins" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">3</th>
<td align="center">September 27</td>
<td align="center">12:00 PM</td>
<td align="center"><a href="/wiki/2009_Green_Bay_Packers_season" title="2009 Green Bay Packers season">Green Bay Packers</a></td>
<td align="center"><b>L</b> 17–36</td>
<td align="center">0–3</td>
<td align="center"><a class="mw-redirect" href="/wiki/Edward_Jones_Dome" title="Edward Jones Dome">Edward Jones Dome</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009092707/2009/REG3/packers@rams" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">4</th>
<td align="center">October 4</td>
<td align="center">3:15 PM</td>
<td align="center">at <b><a href="/wiki/2009_San_Francisco_49ers_season" title="2009 San Francisco 49ers season">San Francisco 49ers</a></b></td>
<td align="center"><b>L</b> 0–35</td>
<td align="center">0–4</td>
<td align="center"><a href="/wiki/Candlestick_Park" title="Candlestick Park">Candlestick Park</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009100411/2009/REG4/rams@49ers" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">5</th>
<td align="center">October 11</td>
<td align="center">12:00 PM</td>
<td align="center"><a href="/wiki/2009_Minnesota_Vikings_season" title="2009 Minnesota Vikings season">Minnesota Vikings</a></td>
<td align="center"><b>L</b> 10–38</td>
<td align="center">0–5</td>
<td align="center"><a class="mw-redirect" href="/wiki/Edward_Jones_Dome" title="Edward Jones Dome">Edward Jones Dome</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009101107/2009/REG5/vikings@rams" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">6</th>
<td align="center">October 18</td>
<td align="center">12:00 PM</td>
<td align="center">at <a href="/wiki/2009_Jacksonville_Jaguars_season" title="2009 Jacksonville Jaguars season">Jacksonville Jaguars</a></td>
<td align="center"><b>L</b> 20–23 <small>(OT)</small></td>
<td align="center">0–6</td>
<td align="center"><a class="mw-redirect" href="/wiki/Jacksonville_Municipal_Stadium" title="Jacksonville Municipal Stadium">Jacksonville Municipal Stadium</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009101802/2009/REG6/rams@jaguars" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">7</th>
<td align="center">October 25</td>
<td align="center">12:00 PM</td>
<td align="center"><a href="/wiki/2009_Indianapolis_Colts_season" title="2009 Indianapolis Colts season">Indianapolis Colts</a></td>
<td align="center"><b>L</b> 6–42</td>
<td align="center">0–7</td>
<td align="center"><a class="mw-redirect" href="/wiki/Edward_Jones_Dome" title="Edward Jones Dome">Edward Jones Dome</a></td>
<td align="center"><a href="/wiki/CBS" title="CBS">CBS</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009102505/2009/REG7/colts@rams" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ddffdd;">
<th align="center">8</th>
<td align="center">November 1</td>
<td align="center">12:00 PM</td>
<td align="center">at <a href="/wiki/2009_Detroit_Lions_season" title="2009 Detroit Lions season">Detroit Lions</a></td>
<td align="center"><b>W</b> 17–10</td>
<td align="center">1–7</td>
<td align="center"><a href="/wiki/Ford_Field" title="Ford Field">Ford Field</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009110104/2009/REG8/rams@lions" rel="nofollow">Recap</a></td>
</tr>
<tr>
<th align="center">9</th>
<td align="center" colspan="9"><a href="/wiki/Bye_(sports)" title="Bye (sports)">Bye</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">10</th>
<td align="center">November 15</td>
<td align="center">12:00 PM</td>
<td align="center"><a href="/wiki/2009_New_Orleans_Saints_season" title="2009 New Orleans Saints season">New Orleans Saints</a></td>
<td align="center"><b>L</b> 23–28</td>
<td align="center">1–8</td>
<td align="center"><a class="mw-redirect" href="/wiki/Edward_Jones_Dome" title="Edward Jones Dome">Edward Jones Dome</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009111505/2009/REG10/saints@rams" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">11</th>
<td align="center">November 22</td>
<td align="center">3:05 PM</td>
<td align="center"><b><a href="/wiki/2009_Arizona_Cardinals_season" title="2009 Arizona Cardinals season">Arizona Cardinals</a></b></td>
<td align="center"><b>L</b> 13–21</td>
<td align="center">1–9</td>
<td align="center"><a class="mw-redirect" href="/wiki/Edward_Jones_Dome" title="Edward Jones Dome">Edward Jones Dome</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009112209/2009/REG11/cardinals@rams" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">12</th>
<td align="center">November 29</td>
<td align="center">12:00 PM</td>
<td align="center"><b><a href="/wiki/2009_Seattle_Seahawks_season" title="2009 Seattle Seahawks season">Seattle Seahawks</a></b></td>
<td align="center"><b>L</b> 17–27</td>
<td align="center">1–10</td>
<td align="center"><a class="mw-redirect" href="/wiki/Edward_Jones_Dome" title="Edward Jones Dome">Edward Jones Dome</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009112907/2009/REG12/seahawks@rams" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">13</th>
<td align="center">December 6</td>
<td align="center">12:00 PM</td>
<td align="center">at <a href="/wiki/2009_Chicago_Bears_season" title="2009 Chicago Bears season">Chicago Bears</a></td>
<td align="center"><b>L</b> 9–17</td>
<td align="center">1–11</td>
<td align="center"><a href="/wiki/Soldier_Field" title="Soldier Field">Soldier Field</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009120602/2009/REG13/rams@bears" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">14</th>
<td align="center">December 13</td>
<td align="center">3:05 PM</td>
<td align="center">at <a href="/wiki/2009_Tennessee_Titans_season" title="2009 Tennessee Titans season">Tennessee Titans</a></td>
<td align="center"><b>L</b> 7–47</td>
<td align="center">1–12</td>
<td align="center"><a class="mw-redirect" href="/wiki/LP_Field" title="LP Field">LP Field</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009121310/2009/REG14/rams@titans" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">15</th>
<td align="center">December 20</td>
<td align="center">12:00 PM</td>
<td align="center"><a href="/wiki/2009_Houston_Texans_season" title="2009 Houston Texans season">Houston Texans</a></td>
<td align="center"><b>L</b> 13–16</td>
<td align="center">1–13</td>
<td align="center"><a class="mw-redirect" href="/wiki/Edward_Jones_Dome" title="Edward Jones Dome">Edward Jones Dome</a></td>
<td align="center"><a href="/wiki/CBS" title="CBS">CBS</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009122007/2009/REG15/texans@rams" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">16</th>
<td align="center">December 27</td>
<td align="center">3:05 PM</td>
<td align="center">at <b><a href="/wiki/2009_Arizona_Cardinals_season" title="2009 Arizona Cardinals season">Arizona Cardinals</a></b></td>
<td align="center"><b>L</b> 10–31</td>
<td align="center">1–14</td>
<td align="center"><a href="/wiki/University_of_Phoenix_Stadium" title="University of Phoenix Stadium">University of Phoenix Stadium</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2009122710/2009/REG16/rams@cardinals" rel="nofollow">Recap</a></td>
</tr>
<tr style="background: #ffdddd;">
<th align="center">17</th>
<td align="center">January 3, 2010</td>
<td align="center">12:00 PM</td>
<td align="center"><b><a href="/wiki/2009_San_Francisco_49ers_season" title="2009 San Francisco 49ers season">San Francisco 49ers</a></b></td>
<td align="center"><b>L</b> 6–28</td>
<td align="center">1–15</td>
<td align="center"><a class="mw-redirect" href="/wiki/Edward_Jones_Dome" title="Edward Jones Dome">Edward Jones Dome</a></td>
<td align="center"><a href="/wiki/Fox_Broadcasting_Company" title="Fox Broadcasting Company">Fox</a></td>
<td align="center"><a class="external text" href="http://www.nfl.com/gamecenter/2010010309/2009/REG17/49ers@rams" rel="nofollow">Recap</a></td>
</tr>
<tr>
<td align="center" colspan="9"><b>NOTE:</b> Division games are in <b>bold</b> text.</td>
</tr>
</tbody></table>

In [6]:
n_columns = 0
n_rows=0
column_names = []
# Find number of rows and columns
# we also find the column titles if we can
for row in table.find_all('tr'):
    # Determine the number of rows in the table
    td_tags = row.find_all('td')
    if len(td_tags) > 0:
        n_rows+=1
        if n_columns == 0:
            # Set the number of columns for our table
            n_columns = len(td_tags)
                        
    # Handle column names if we find them
    th_tags = row.find_all('th') 
    if len(th_tags) > 0 and len(column_names) == 0:
        for th in th_tags:
            column_names.append(th.get_text())
                    
# Safeguard on Column Titles
if len(column_names) > 0 and len(column_names) != n_columns:
    raise Exception("Column titles do not match the number of columns")
    
columns = column_names if len(column_names) > 0 else range(0,n_columns)
Rams09df = pd.DataFrame(columns = columns, index= range(0,n_rows))
row_marker = 0
for row in table.find_all('tr'):
    column_marker = 0
    columns = row.find_all('td')
    for column in columns:
        Rams09df.iat[row_marker,column_marker] = column.get_text()
        column_marker += 1
    if len(columns) > 0:
        row_marker += 1

In [7]:
Rams09df


Out[7]:
Week Date Kickoff (CT) Opponent Results Game Site TV NFL Recap
0 September 13 3:15 PM at Seattle Seahawks L 0–28 0–1 Qwest Field Fox Recap
1 September 20 12:00 PM at Washington Redskins L 7–9 0–2 FedExField Fox Recap
2 September 27 12:00 PM Green Bay Packers L 17–36 0–3 Edward Jones Dome Fox Recap
3 October 4 3:15 PM at San Francisco 49ers L 0–35 0–4 Candlestick Park Fox Recap
4 October 11 12:00 PM Minnesota Vikings L 10–38 0–5 Edward Jones Dome Fox Recap
5 October 18 12:00 PM at Jacksonville Jaguars L 20–23 (OT) 0–6 Jacksonville Municipal Stadium Fox Recap
6 October 25 12:00 PM Indianapolis Colts L 6–42 0–7 Edward Jones Dome CBS Recap
7 November 1 12:00 PM at Detroit Lions W 17–10 1–7 Ford Field Fox Recap
8 Bye NaN NaN NaN NaN NaN NaN NaN
9 November 15 12:00 PM New Orleans Saints L 23–28 1–8 Edward Jones Dome Fox Recap
10 November 22 3:05 PM Arizona Cardinals L 13–21 1–9 Edward Jones Dome Fox Recap
11 November 29 12:00 PM Seattle Seahawks L 17–27 1–10 Edward Jones Dome Fox Recap
12 December 6 12:00 PM at Chicago Bears L 9–17 1–11 Soldier Field Fox Recap
13 December 13 3:05 PM at Tennessee Titans L 7–47 1–12 LP Field Fox Recap
14 December 20 12:00 PM Houston Texans L 13–16 1–13 Edward Jones Dome CBS Recap
15 December 27 3:05 PM at Arizona Cardinals L 10–31 1–14 University of Phoenix Stadium Fox Recap
16 January 3, 2010 12:00 PM San Francisco 49ers L 6–28 1–15 Edward Jones Dome Fox Recap
17 NOTE: Division games are in bold text. NaN NaN NaN NaN NaN NaN NaN

In [8]:
soup =BeautifulSoup(urllib.request.urlopen('https://en.wikipedia.org/wiki/2000_San_Diego_Chargers_season').read())
table = soup.find_all("table", { "class" : "wikitable" })[0]
print(table)


/opt/conda/lib/python3.5/site-packages/bs4/__init__.py:181: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html5lib"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 184 of the file /opt/conda/lib/python3.5/runpy.py. To get rid of this warning, change code that looks like this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "html5lib")

  markup_type=markup_type))
<table class="wikitable">
<tbody><tr>
<th>Week</th>
<th>Date</th>
<th>Opponent</th>
<th>Result</th>
<th>Game site</th>
<th>Record</th>
<th>Attendance</th>
</tr>
<tr style="background: #ffdddd;">
<td>1</td>
<td>September 3, 2000</td>
<td>at <a href="/wiki/Oakland_Raiders" title="Oakland Raiders">Oakland Raiders</a></td>
<td><b>L</b> 6–9</td>
<td><a class="mw-redirect" href="/wiki/Network_Associates_Coliseum" title="Network Associates Coliseum">Network Associates Coliseum</a></td>
<td align="center" colspan="1">0–1</td>
<td>
<center>56,373</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>2</td>
<td>September 10, 2000</td>
<td><a href="/wiki/New_Orleans_Saints" title="New Orleans Saints">New Orleans Saints</a></td>
<td><b>L</b> 27–28</td>
<td><a href="/wiki/Qualcomm_Stadium" title="Qualcomm Stadium">Qualcomm Stadium</a></td>
<td align="center" colspan="1">0–2</td>
<td>
<center>51,300</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>3</td>
<td>September 17, 2000</td>
<td>at <a href="/wiki/Kansas_City_Chiefs" title="Kansas City Chiefs">Kansas City Chiefs</a></td>
<td><b>L</b> 10–42</td>
<td><a href="/wiki/Arrowhead_Stadium" title="Arrowhead Stadium">Arrowhead Stadium</a></td>
<td align="center" colspan="1">0–3</td>
<td>
<center>77,604</center>
</td>
</tr>
<tr style="background: #ffdddd">
<td>4</td>
<td>September 24, 2000</td>
<td><a href="/wiki/Seattle_Seahawks" title="Seattle Seahawks">Seattle Seahawks</a></td>
<td><b>L</b> 12–20</td>
<td><a href="/wiki/Qualcomm_Stadium" title="Qualcomm Stadium">Qualcomm Stadium</a></td>
<td align="center" colspan="1">0–4</td>
<td>
<center>47,233</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>5</td>
<td>October 1, 2000</td>
<td>at <a class="mw-redirect" href="/wiki/St._Louis_Rams" title="St. Louis Rams">St. Louis Rams</a></td>
<td><b>L</b> 31–57</td>
<td><a class="mw-redirect" href="/wiki/Trans_World_Dome" title="Trans World Dome">Trans World Dome</a></td>
<td align="center" colspan="1">0–5</td>
<td>
<center>66,010</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>6</td>
<td>October 8, 2000</td>
<td><a href="/wiki/Denver_Broncos" title="Denver Broncos">Denver Broncos</a></td>
<td><b>L</b> 7–21</td>
<td><a href="/wiki/Qualcomm_Stadium" title="Qualcomm Stadium">Qualcomm Stadium</a></td>
<td align="center" colspan="1">0–6</td>
<td>
<center>56,079</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>7</td>
<td>October 15, 2000</td>
<td>at <a href="/wiki/Buffalo_Bills" title="Buffalo Bills">Buffalo Bills</a></td>
<td><b>L</b> 24–27</td>
<td><a class="mw-redirect" href="/wiki/Ralph_Wilson_Stadium" title="Ralph Wilson Stadium">Ralph Wilson Stadium</a></td>
<td align="center" colspan="1">0–7</td>
<td>
<center>72,351</center>
</td>
</tr>
<tr>
<td>8</td>
<td>October 22, 2000</td>
<td align="center" colspan="6"><i>Bye</i></td>
</tr>
<tr style="background: #ffdddd;">
<td>9</td>
<td>October 29, 2000</td>
<td><a href="/wiki/Oakland_Raiders" title="Oakland Raiders">Oakland Raiders</a></td>
<td><b>L</b> 13–15</td>
<td><a href="/wiki/Qualcomm_Stadium" title="Qualcomm Stadium">Qualcomm Stadium</a></td>
<td align="center" colspan="1">0–8</td>
<td>
<center>66,659</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>10</td>
<td>November 5, 2000</td>
<td>at <a href="/wiki/Seattle_Seahawks" title="Seattle Seahawks">Seattle Seahawks</a></td>
<td><b>L</b> 15–17</td>
<td><a href="/wiki/Husky_Stadium" title="Husky Stadium">Husky Stadium</a></td>
<td align="center" colspan='1"'>0–9</td>
<td>
<center>59,884</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>11</td>
<td>November 12, 2000</td>
<td><a href="/wiki/Miami_Dolphins" title="Miami Dolphins">Miami Dolphins</a></td>
<td><b>L</b> 7–17</td>
<td><a href="/wiki/Qualcomm_Stadium" title="Qualcomm Stadium">Qualcomm Stadium</a></td>
<td align="center" colspan="1">0–10</td>
<td>
<center>56,896</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>12</td>
<td>November 19, 2000</td>
<td>at <a href="/wiki/Denver_Broncos" title="Denver Broncos">Denver Broncos</a></td>
<td><b>L</b> 37–38</td>
<td><a href="/wiki/Mile_High_Stadium" title="Mile High Stadium">Mile High Stadium</a></td>
<td align="center" colspan="1">0–11</td>
<td>
<center>75,218</center>
</td>
</tr>
<tr style="background: #bbffbb;">
<td>13</td>
<td>November 26, 2000</td>
<td><a href="/wiki/Kansas_City_Chiefs" title="Kansas City Chiefs">Kansas City Chiefs</a></td>
<td><b>W</b> 17–16</td>
<td><a href="/wiki/Qualcomm_Stadium" title="Qualcomm Stadium">Qualcomm Stadium</a></td>
<td align="center" colspan="1">1–11</td>
<td>
<center>47,228</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>14</td>
<td>December 3, 2000</td>
<td><a href="/wiki/San_Francisco_49ers" title="San Francisco 49ers">San Francisco 49ers</a></td>
<td><b>L</b> 17–45</td>
<td><a href="/wiki/Qualcomm_Stadium" title="Qualcomm Stadium">Qualcomm Stadium</a></td>
<td align="center" colspan="1">1–12</td>
<td>
<center>57,255</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>15</td>
<td>December 10, 2000</td>
<td>at <a href="/wiki/Baltimore_Ravens" title="Baltimore Ravens">Baltimore Ravens</a></td>
<td><b>L</b> 3–24</td>
<td><a href="/wiki/M%26T_Bank_Stadium" title="M&amp;T Bank Stadium">PSINet Stadium</a></td>
<td align="center">1–13</td>
<td>
<center>68,805</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>16</td>
<td>December 17, 2000</td>
<td>at <a href="/wiki/Carolina_Panthers" title="Carolina Panthers">Carolina Panthers</a></td>
<td><b>L</b> 22–30</td>
<td><a href="/wiki/Bank_of_America_Stadium" title="Bank of America Stadium">Ericsson Stadium</a></td>
<td align="center">1–14</td>
<td>
<center>72,159</center>
</td>
</tr>
<tr style="background: #ffdddd;">
<td>17</td>
<td>December 24, 2000</td>
<td><a href="/wiki/Pittsburgh_Steelers" title="Pittsburgh Steelers">Pittsburgh Steelers</a></td>
<td><b>L</b> 21–34</td>
<td><a href="/wiki/Qualcomm_Stadium" title="Qualcomm Stadium">Qualcomm Stadium</a></td>
<td align="center">1–15</td>
<td>
<center>50,809</center>
</td>
</tr>
</tbody></table>

In [9]:
n_columns = 0
n_rows=0
column_names = []
# Find number of rows and columns
# we also find the column titles if we can
for row in table.find_all('tr'):
    # Determine the number of rows in the table
    td_tags = row.find_all('td')
    if len(td_tags) > 0:
        n_rows+=1
        if n_columns == 0:
            # Set the number of columns for our table
            n_columns = len(td_tags)
                        
    # Handle column names if we find them
    th_tags = row.find_all('th') 
    if len(th_tags) > 0 and len(column_names) == 0:
        for th in th_tags:
            column_names.append(th.get_text())
                    
# Safeguard on Column Titles
if len(column_names) > 0 and len(column_names) != n_columns:
    raise Exception("Column titles do not match the number of columns")
    
columns = column_names if len(column_names) > 0 else range(0,n_columns)
Carg00df = pd.DataFrame(columns = columns, index= range(0,n_rows))
row_marker = 0
for row in table.find_all('tr'):
    column_marker = 0
    columns = row.find_all('td')
    for column in columns:
        Carg00df.iat[row_marker,column_marker] = column.get_text()
        column_marker += 1
    if len(columns) > 0:
        row_marker += 1

In [10]:
Carg00df


Out[10]:
Week Date Opponent Result Game site Record Attendance
0 1 September 3, 2000 at Oakland Raiders L 6–9 Network Associates Coliseum 0–1 \n56,373\n
1 2 September 10, 2000 New Orleans Saints L 27–28 Qualcomm Stadium 0–2 \n51,300\n
2 3 September 17, 2000 at Kansas City Chiefs L 10–42 Arrowhead Stadium 0–3 \n77,604\n
3 4 September 24, 2000 Seattle Seahawks L 12–20 Qualcomm Stadium 0–4 \n47,233\n
4 5 October 1, 2000 at St. Louis Rams L 31–57 Trans World Dome 0–5 \n66,010\n
5 6 October 8, 2000 Denver Broncos L 7–21 Qualcomm Stadium 0–6 \n56,079\n
6 7 October 15, 2000 at Buffalo Bills L 24–27 Ralph Wilson Stadium 0–7 \n72,351\n
7 8 October 22, 2000 Bye NaN NaN NaN NaN
8 9 October 29, 2000 Oakland Raiders L 13–15 Qualcomm Stadium 0–8 \n66,659\n
9 10 November 5, 2000 at Seattle Seahawks L 15–17 Husky Stadium 0–9 \n59,884\n
10 11 November 12, 2000 Miami Dolphins L 7–17 Qualcomm Stadium 0–10 \n56,896\n
11 12 November 19, 2000 at Denver Broncos L 37–38 Mile High Stadium 0–11 \n75,218\n
12 13 November 26, 2000 Kansas City Chiefs W 17–16 Qualcomm Stadium 1–11 \n47,228\n
13 14 December 3, 2000 San Francisco 49ers L 17–45 Qualcomm Stadium 1–12 \n57,255\n
14 15 December 10, 2000 at Baltimore Ravens L 3–24 PSINet Stadium 1–13 \n68,805\n
15 16 December 17, 2000 at Carolina Panthers L 22–30 Ericsson Stadium 1–14 \n72,159\n
16 17 December 24, 2000 Pittsburgh Steelers L 21–34 Qualcomm Stadium 1–15 \n50,809\n

In [11]:
Carg00df['pointsfor'] = Carg00df['Result'].str.extract('(\d+)', expand=True)
Carg00df['pointsAgainst'] = Carg00df['Result'].str.extract('(\d+$)', expand=True)
Rams09df['pointsfor'] = Rams09df['Opponent'].str.extract('(\d+)', expand=True)
Rams09df['Opponent'] = Rams09df['Opponent'].str.strip("(\s\([OT]\)$)")
Rams09df['pointsAgainst'] = Rams09df['Opponent'].str.extract('(\d+$)', expand=True)
lions08df['pointsfor'] = lions08df['Opponent'].str.extract('(\d+)', expand=True)
lions08df['pointsAgainst'] = lions08df['Opponent'].str.extract('(\d+$)', expand=True)

In [12]:
Rams09df['pointsAgainst'][5] = 23

In [13]:
lions08df.dropna(inplace=True)
Rams09df.dropna(inplace=True)
Carg00df.dropna(inplace=True)

In [14]:
Carg00df['pointsfor'] = Carg00df['pointsfor'].astype(int)
Carg00df['pointsAgainst'] = Carg00df['pointsAgainst'].astype(int)
Rams09df['pointsfor'] = Rams09df['pointsfor'].astype(int)
Rams09df['pointsAgainst'] = Rams09df['pointsAgainst'].astype(int)
lions08df['pointsfor'] = lions08df['pointsfor'].astype(int)
lions08df['pointsAgainst'] = lions08df['pointsAgainst'].astype(int)

In [15]:
Carg00df['NetPoints'] = Carg00df['pointsfor'] - Carg00df['pointsAgainst']
Rams09df['NetPoints'] = Rams09df['pointsfor'] - Rams09df['pointsAgainst']
lions08df['NetPoints'] = lions08df['pointsfor'] - lions08df['pointsAgainst']

In [16]:
Carg00df['Average'] = Carg00df['NetPoints'].mean()
Rams09df['Average'] = Rams09df['NetPoints'].mean()
lions08df['Average'] = lions08df['NetPoints'].mean()

In [17]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sb

%matplotlib notebook

In [49]:
plt.figure()
#plt.subplot(axisbg='lavenderblush', alpha=0.9)
plt.plot(lions08df['NetPoints'], label="Lions 2008", alpha=0.2, color='b', ls='--')
plt.plot(Rams09df['NetPoints'], label="Rams 2009", alpha=0.3, color='gold', ls='--')
plt.plot(Carg00df['NetPoints'], label="Panthers 2000", alpha=0.2, color='c', ls='--')
plt.plot(lions08df['Average'], label="Average Lions 2008", color='b', alpha=0.8)
plt.plot(Rams09df['Average'], label="Average Rams 2009", color='gold', alpha=0.8)
plt.plot(Carg00df['Average'], label="Average Panthers 2000", color='c', alpha=0.8)
plt.legend()
plt.xlim((0,16))
plt.ylim((-40,5))
plt.xlabel('Week')
plt.ylabel('Net Point Differential')
plt.title('Comparison of the Winless Lions Against single Win Teams')
plt.grid(b=False)