Skip to content

Instantly share code, notes, and snippets.

Last active Sep 9, 2016
What would you like to do?
Use Pandas to download html table of bear sightings in CT and save to bears.csv
import pandas as pd
class BearTable():
BearTable() - get a pandas DataFrame() of bear sightings in CT
This is a rolling list of bear sightings maintained by the CT
Department of Energy and Environmental protection. It is
available online at:
This tool will fail if the structure of that web page changes
from when this tool was designed.
def __init__(self):
self.table = False
self.url = ""
tables = pd.read_html(self.url)
# print "Found " + str(len(tables)) + " tables."
table = tables[11]
if (len(table.columns) != 2):
raise Exception("This table doesn't look right. Maybe the page has been changed")
table.columns = "Town","Reports"
self.table = table
def get(self):
return self.table
# Do the same thing, but in 4 lines
import pandas as pd
table = pd.read_html("")[11]
table.columns = "Towns","Reports"
table.to_csv("bears.csv", index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment