# import a library for openning URL import urllib.request # We'll work with a dataset from the Internet. This dataset contains history temperature # # http://www.wunderground.com/history/airport/KCHO/2012/03/17/DailyHistory.html?format=1" # # Typically, we'd want to be able to access multiple day-month-year of this history file, # put day-month-year in variables and form a URL # Or, sometimes we'd want to let the user specify what date to load data # # prepare URL to be opened year = "2012" month = "03" day = "17" url = "http://www.wunderground.com/history/airport/KCHO/" + year + "/" + month +"/" + day + "/DailyHistory.html?format=1" # how about yesterday's weather # open the specified URL to read # store the response object received from the server in a variable stream = urllib.request.urlopen(url) print(stream) # http.client.HTTPResponse object print("processing data") is_header = True # read each line from the response object for line in stream: # decode the string using the standard encoding scheme (UTF-8) # then, strip leading and tailing spaces, and split the string using "," decoded = line.decode("UTF-8").strip().split(",") print(decoded) # there is "
" at the end of each line ## what can we do with this dataset? # Count how many days the weather was clear # Compute the average temperatureF # Find patterns and estimate likelihood print("processing data") is_header = True # read each line from the response object for line in stream: # decode the string using the standard encoding scheme (UTF-8) # then, strip leading and tailing spaces, and split the string using "," decoded = line.decode("UTF-8").strip().split(",") print(decoded) # there is "
" at the end of each line ## what can we do with this dataset? # Count how many days the weather was clear # Compute the average temperatureF # Find patterns and estimate likelihood