Erin Orbits
Project Due: Oct 19, 2017

#https://github.com/orbitse/data-512-a1/blob/master/hcds-a1-data-curation.ipynb
"""
The code in this cell is optional. You don't need to run this cell
in order to run the code in subsequent cells.
"""

# This code displays all results created within a jupyter notebook cell.
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

# This code displays Matplotlib objects inline.
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')
import csv
import json
import requests

json_file_names = ["pagecounts_desktop-site_200801-201607.json",
                   "pagecounts_mobile-site_200801-201607.json",
                   "pageviews_desktop_201508-201709.json",
                   "pageviews_mobile_201508-201709.json",
                   "pageviews_mobile-web_201508-201709.json"]


params_pageviews = {"project" : "en.wikipedia.org",
                    "access" : "desktop", # or "mobile-app" or "mobile-web"
                    "agent" : "user",
                    "granularity" : "monthly",
                    "start" : "2015080100",
                    # use 1st day of following month to collect a full month of data
                    "end" : '2017101000'
                    }

params_pagecounts = {"project" : "en.wikipedia.org",
                     "access" : "desktop-site", # or "mobile-site"
                     "granularity" : "monthly",
                     "start" : "2008010100",
                     # use 1st day of following month to collect a full month of data
                     "end" : "2017100100"
                    }

def api_call(api_type="pageview",
             parameters=params_pageviews, file_name="api_file.json"):
    """
    :param api_type: sets the Wikipedia API for the GET request,
                     the default value is "pageview"
    :param parameters: sets the values for the GET request,
                       the default value is params_pageviews
    :param file_name: sets the JSON file name for saving data,
                      the default value is the file name api_file.json 
    :returns: JSON file
    This function calls the API and gets a JSON response in a
    format like this:
        {"items":[{"project":"en.wikipedia","access-site":"desktop-site",
                   "granularity":"monthly","timestamp":"2008010100",
                   "count":4930902570},...]}
    """
    if api_type == "pageview":
        # Pageview endpoint to be modified during API calls.
        endpoint_pageview = 'https://wikimedia.org/api/rest_v1/metrics/pageviews/aggregate/{project}/{access}/{agent}/{granularity}/{start}/{end}'
        api_call = requests.get(endpoint_pageview.format(**parameters))
    elif api_type == "pagecount":
        # Pagecount endpoint to be modified during API calls.
        endpoint_pagecount = 'https://wikimedia.org/api/rest_v1/metrics/legacy/pagecounts/aggregate/{project}/{access}/{granularity}/{start}/{end}'
        api_call = requests.get(endpoint_pagecount.format(**parameters))
    else:
        print("Unable to submit API request. Please try again.")  
    
    # Submits GET request and saves JSON response
    response = api_call.json()   
    
    # Saves JSON file
    with open(file_name, "w") as file:
        json.dump(response, file)
    
    # Notifies user that JSON file was saved.
    print("Saved File:", str(file_name))
    
    # Returns the JSON response
    return(response)


# Calls api_call() function to get data from Pageview API
pageview_access = ["desktop", "mobile-app", "mobile-web"]
for item in pageview_access:
    params_pageviews["access"] = item
    api_call(api_type="pageview", parameters=params_pageviews,
             file_name="pageviews_"+str(item)+"_201508-201709.json")

# Calls api_call() function to get data from Pagecount API
pagecount_access = ["desktop-site","mobile-site"]
for item in pagecount_access:
    params_pagecounts["access"] = item
    api_call(api_type="pagecount", parameters=params_pagecounts,
             file_name="pagecounts_"+str(item)+"_200801-201607.json")
Saved File: pageviews_desktop_201508-201709.json
{'items': [{'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015080100',
   'views': 4332482183},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015090100',
   'views': 4485491704},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015100100',
   'views': 4477532755},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015110100',
   'views': 4287720220},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015120100',
   'views': 4100012037},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016010100',
   'views': 4436179457},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016020100',
   'views': 4250997185},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016030100',
   'views': 4286590426},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016040100',
   'views': 4149383857},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016050100',
   'views': 4191778094},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016060100',
   'views': 3888839711},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016070100',
   'views': 4337865827},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016080100',
   'views': 4695046216},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016090100',
   'views': 4135006498},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016100100',
   'views': 4361737690},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016110100',
   'views': 4392068236},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016120100',
   'views': 4209608578},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017010100',
   'views': 4521980398},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017020100',
   'views': 4026702163},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017030100',
   'views': 4319971902},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017040100',
   'views': 3951456992},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017050100',
   'views': 4187870579},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017060100',
   'views': 3604550997},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017070100',
   'views': 3565444544},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017080100',
   'views': 3575572313},
  {'project': 'en.wikipedia',
   'access': 'desktop',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017090100',
   'views': 3547447892}]}
Saved File: pageviews_mobile-app_201508-201709.json
{'items': [{'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015080100',
   'views': 109669149},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015090100',
   'views': 96221684},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015100100',
   'views': 94523777},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015110100',
   'views': 94353925},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015120100',
   'views': 99438956},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016010100',
   'views': 106432767},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016020100',
   'views': 92414130},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016030100',
   'views': 97899074},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016040100',
   'views': 81719003},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016050100',
   'views': 98738513},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016060100',
   'views': 96908466},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016070100',
   'views': 101398640},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016080100',
   'views': 97172509},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016090100',
   'views': 83037939},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016100100',
   'views': 67174886},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016110100',
   'views': 83623769},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016120100',
   'views': 128976033},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017010100',
   'views': 211813191},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017020100',
   'views': 189059134},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017030100',
   'views': 184098693},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017040100',
   'views': 115051969},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017050100',
   'views': 118805669},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017060100',
   'views': 115285847},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017070100',
   'views': 124118219},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017080100',
   'views': 119171796},
  {'project': 'en.wikipedia',
   'access': 'mobile-app',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017090100',
   'views': 114615188}]}
Saved File: pageviews_mobile-web_201508-201709.json
{'items': [{'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015080100',
   'views': 3192663889},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015090100',
   'views': 3073981649},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015100100',
   'views': 3173975355},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015110100',
   'views': 3142247145},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2015120100',
   'views': 3276836351},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016010100',
   'views': 3611404079},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016020100',
   'views': 3242448142},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016030100',
   'views': 3288785117},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016040100',
   'views': 3177044999},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016050100',
   'views': 3296294723},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016060100',
   'views': 3257882479},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016070100',
   'views': 3395175122},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016080100',
   'views': 3418646794},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016090100',
   'views': 3310247842},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016100100',
   'views': 3442109005},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016110100',
   'views': 3507421156},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2016120100',
   'views': 3647567822},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017010100',
   'views': 4020148351},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017020100',
   'views': 3522702265},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017030100',
   'views': 3719395296},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017040100',
   'views': 3524571150},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017050100',
   'views': 3567882051},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017060100',
   'views': 3404097346},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017070100',
   'views': 3600941034},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017080100',
   'views': 3502234506},
  {'project': 'en.wikipedia',
   'access': 'mobile-web',
   'agent': 'user',
   'granularity': 'monthly',
   'timestamp': '2017090100',
   'views': 3416989181}]}
Saved File: pagecounts_desktop-site_200801-201607.json
{'items': [{'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008010100',
   'count': 4930902570},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008020100',
   'count': 4818393763},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008030100',
   'count': 4955405809},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008040100',
   'count': 5159162183},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008050100',
   'count': 5584691092},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008060100',
   'count': 5712104279},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008070100',
   'count': 5306302874},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008080100',
   'count': 5140155519},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008090100',
   'count': 5479533823},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008100100',
   'count': 5679440782},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008110100',
   'count': 5415832071},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2008120100',
   'count': 5211708451},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009010100',
   'count': 5802681551},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009020100',
   'count': 5547320860},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009030100',
   'count': 6295159057},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009040100',
   'count': 5988817321},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009050100',
   'count': 6267516733},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009060100',
   'count': 5818924182},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009070100',
   'count': 5801646978},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009080100',
   'count': 5790850384},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009090100',
   'count': 4057515768},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009100100',
   'count': 6016107147},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009110100',
   'count': 5768486910},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2009120100',
   'count': 5426505977},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010010100',
   'count': 5703465285},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010020100',
   'count': 5762451418},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010030100',
   'count': 6661347946},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010040100',
   'count': 6618552152},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010050100',
   'count': 6410578775},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010060100',
   'count': 4898035014},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010070100',
   'count': 5296177638},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010080100',
   'count': 7381346660},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010090100',
   'count': 7546488744},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010100100',
   'count': 10172844562},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010110100',
   'count': 6948678354},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2010120100',
   'count': 7001952100},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011010100',
   'count': 7568511227},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011020100',
   'count': 6906248849},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011030100',
   'count': 7326545928},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011040100',
   'count': 6835492088},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011050100',
   'count': 7009799378},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011060100',
   'count': 6536675534},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011070100',
   'count': 6571730164},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011080100',
   'count': 6514500361},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011090100',
   'count': 5837738935},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011100100',
   'count': 6974424665},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011110100',
   'count': 7507641641},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2011120100',
   'count': 6396357939},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012010100',
   'count': 7808477339},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012020100',
   'count': 7530127141},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012030100',
   'count': 7358543625},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012040100',
   'count': 7220029422},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012050100',
   'count': 7784479302},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012060100',
   'count': 7524265988},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012070100',
   'count': 7819376527},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012080100',
   'count': 7885641059},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012090100',
   'count': 7913689733},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012100100',
   'count': 8379960050},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012110100',
   'count': 8219987195},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2012120100',
   'count': 8033826900},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013010100',
   'count': 9126210673},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013020100',
   'count': 8100597857},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013030100',
   'count': 8701419671},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013040100',
   'count': 8049296729},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013050100',
   'count': 8089099883},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013060100',
   'count': 7759959725},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013070100',
   'count': 8237301982},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013080100',
   'count': 9306122925},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013090100',
   'count': 9985326806},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013100100',
   'count': 10775158269},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013110100',
   'count': 10414877805},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2013120100',
   'count': 7102459747},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014010100',
   'count': 7026531269},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014020100',
   'count': 6718243109},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014030100',
   'count': 7464128273},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014040100',
   'count': 7216245221},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014050100',
   'count': 7543277646},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014060100',
   'count': 6577352648},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014070100',
   'count': 6761059566},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014080100',
   'count': 6687313714},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014090100',
   'count': 7564600999},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014100100',
   'count': 6577533128},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014110100',
   'count': 6153537606},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2014120100',
   'count': 5830332248},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015010100',
   'count': 6103767055},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015020100',
   'count': 5602710439},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015030100',
   'count': 6346602713},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015040100',
   'count': 6198945657},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015050100',
   'count': 6323801814},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015060100',
   'count': 5165413640},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015070100',
   'count': 5229226022},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015080100',
   'count': 5035534449},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015090100',
   'count': 5409631355},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015100100',
   'count': 5535704471},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015110100',
   'count': 5296956116},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2015120100',
   'count': 5264446173},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2016010100',
   'count': 5569632502},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2016020100',
   'count': 5347709361},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2016030100',
   'count': 5407676056},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2016040100',
   'count': 5572235399},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2016050100',
   'count': 5330532334},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2016060100',
   'count': 4975092447},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2016070100',
   'count': 5363966439},
  {'project': 'en.wikipedia',
   'access-site': 'desktop-site',
   'granularity': 'monthly',
   'timestamp': '2016080100',
   'count': 913675893}]}
Saved File: pagecounts_mobile-site_200801-201607.json
{'items': [{'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2014100100',
   'count': 3091546685},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2014110100',
   'count': 3027489668},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2014120100',
   'count': 3278950021},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015010100',
   'count': 3485302091},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015020100',
   'count': 3091534479},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015030100',
   'count': 3330832588},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015040100',
   'count': 3222089917},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015050100',
   'count': 3334069483},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015060100',
   'count': 3038162463},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015070100',
   'count': 3254472695},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015080100',
   'count': 3268487582},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015090100',
   'count': 3172429827},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015100100',
   'count': 3246082505},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015110100',
   'count': 3218234512},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2015120100',
   'count': 3387411863},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2016010100',
   'count': 3739628742},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2016020100',
   'count': 3333231392},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2016030100',
   'count': 3419853636},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2016040100',
   'count': 3301385124},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2016050100',
   'count': 3418435805},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2016060100',
   'count': 3372618063},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2016070100',
   'count': 3500661121},
  {'project': 'en.wikipedia',
   'access-site': 'mobile-site',
   'granularity': 'monthly',
   'timestamp': '2016080100',
   'count': 480041296}]}

Step 2: Data processing

In this step, we perform a series of processing steps on the saved JSON data files generated by the API requests. This processing is being done to prepare the data for analysis and combine the relevant features into a single CSV-formatted data file.

The processing will include:

  • extracting the year (YYYY) and month (MM) from the timestamp data;
  • setting null values to 0;
  • creating columns with total page views from each API; and
  • adding together the monthly views from the mobile-app and mobile-web sources to create a total mobile traffic count for each month.

The final, consolidated data file is named: en-wikipedia_traffic_200801-201709.csv

import csv
import json
import pandas as pd

OUTPUT_FILE = "en-wikipedia_traffic_200801-201709.csv"

JSON_FILES = ["pagecounts_desktop-site_200801-201607.json",
              "pagecounts_mobile-site_200801-201607.json",
              "pageviews_desktop_201508-201709.json",
              "pageviews_mobile-app_201508-201709.json",
              "pageviews_mobile-web_201508-201709.json"]

# This dictionary is more for reference since intermediate
# DataFrames are named in the format: DICT_DF[count]
DICT_DF = {0 : "pagecounts_desktop_df",
           1 : "pagecounts_mobile_df",
           2 : "pageviews_desktop_df",
           3 : "pageviews_mobileapp_df",
           4 : "pageviews_mobileweb_df"}

count = 0 

# Loop through JSON files for processing
for jfile in JSON_FILES:
    
    with open(jfile, encoding="utf-8") as data_file:
        
        dict_data = json.load(data_file) # dictionary object
        extracted_items = dict_data["items"] # a list object
        
        # Create a DataFrame with "keys" as column names.
        DICT_DF[count] = pd.DataFrame.from_dict(extracted_items)
        
    # Create columns for year and month in DataFrame.
    DICT_DF[count]["year"] = DICT_DF[count]["timestamp"].str[0:4]
    DICT_DF[count]["month"] = DICT_DF[count]["timestamp"].str[4:6]
        
    # Standardize "access" and "access-site" columns to "access."
    if "access-site" in DICT_DF[count].columns:
        DICT_DF[count].rename(columns={"access-site" : "access"}, inplace=True)
        
    # Get the source of page view traffic.
    traffic_source = DICT_DF[count].get_value(index=1, col="access")
        
    # Rename count or views column with specific name.
    if traffic_source == "desktop-site":
        DICT_DF[count].rename(index=str,
                              columns={"count" : "pagecount_desktop_views",
                                       "views" : "pagecount_desktop_views"},
                              inplace=True)
    elif traffic_source == "mobile-site":
        DICT_DF[count].rename(index=str,
                              columns={"count" : "pagecount_mobile_views",
                                       "views" : "pagecount_mobile_views"},
                              inplace=True)
    elif traffic_source == "desktop":
        DICT_DF[count].rename(index=str,
                              columns={"count" : "pageview_desktop_views",
                                       "views" : "pageview_desktop_views"},
                              inplace=True)
    elif traffic_source == "mobile-app":        
        DICT_DF[count].rename(index=str,
                              columns={"count" : "pageview_mobile_views",
                                       "views" : "pageview_mobile_views"},
                              inplace=True)
    elif traffic_source == "mobile-web":
        DICT_DF[count].rename(index=str,
                              columns={"count" : "pageview_mobile_views",
                                       "views" : "pageview_mobile_views"},
                              inplace=True)

    # If DataFrame includes an "agent" column, then drop these columns.
    if "agent" in DICT_DF[count].columns:
        # The axis number is 0 for rows and 1 for columns.
        # To delete DataFrame columns w/o reassigning, use inplace=True. 
        DICT_DF[count].drop(["access", "granularity", "agent", "project", "timestamp"],
                             axis=1, inplace=True)
            
    # If DataFrame doesn't include "agent" column, then drop these columns.
    else:
        DICT_DF[count].drop(["access", "granularity", "project", "timestamp"],
                             axis=1, inplace=True)
        
    # Increment the counter for initial DataFrame names.    
    count = count + 1

    
# Merge the pagecount DataFrames, change NA values to 0, and
# add "pagecount_all_views" column.
df_pagecount = DICT_DF[0].merge(DICT_DF[1], how='outer',
                                on=["year", "month"])
df_pagecount = df_pagecount.fillna(0)
df_pagecount["pagecount_all_views"] = df_pagecount["pagecount_desktop_views"] + df_pagecount["pagecount_mobile_views"]

# Merge the pageview DataFrames, change NA values to 0, and
# add "pageview_all_views" column.
df_mobile = DICT_DF[3].merge(DICT_DF[4], how='outer',
                             on=["year", "month"])
df_mobile["pageview_mobile_views"] = df_mobile["pageview_mobile_views_x"] + df_mobile["pageview_mobile_views_y"]  
df_mobile.drop(["pageview_mobile_views_x", "pageview_mobile_views_y"],
               axis=1, inplace=True)
df_pageview = df_mobile.merge(DICT_DF[2], how='outer',
                              on=["year", "month"])
df_pageview = df_pageview.fillna(0)
df_pageview["pageview_all_views"] = df_pageview["pageview_mobile_views"] + df_pageview["pageview_desktop_views"]

# Merge the pagecount and pageview DataFrames, and keep NA values as 0.
df_final = df_pagecount.merge(df_pageview, how='outer',
                              on=["year", "month"])
df_final = df_final.fillna(0).astype(int)

# Reorder the columns in the final DataFrame.
df_final = df_final[["year", "month", "pagecount_all_views",
                     "pagecount_desktop_views", "pagecount_mobile_views",
                     "pageview_all_views", "pageview_desktop_views",
                     "pageview_mobile_views"]]

# Remove original index and reset index as a multi-column index.
df_yr_mo_index = df_final.set_index(["year", "month"])

# Write final version of DataFrame w/o separate index to CSV file.
df_yr_mo_index.to_csv(OUTPUT_FILE, sep=",", encoding='utf-8')

# Display first 25 rows of combined DataFrame.
df_final.head(25)
/srv/paws/lib/python3.6/site-packages/ipykernel_launcher.py:43: FutureWarning: get_value is deprecated and will be removed in a future release. Please use .at[] or .iat[] accessors instead
year month pagecount_all_views pagecount_desktop_views pagecount_mobile_views pageview_all_views pageview_desktop_views pageview_mobile_views
0 2008 1 4930902570 4930902570 0 0 0 0
1 2008 2 4818393763 4818393763 0 0 0 0
2 2008 3 4955405809 4955405809 0 0 0 0
3 2008 4 5159162183 5159162183 0 0 0 0
4 2008 5 5584691092 5584691092 0 0 0 0
5 2008 6 5712104279 5712104279 0 0 0 0
6 2008 7 5306302874 5306302874 0 0 0 0
7 2008 8 5140155519 5140155519 0 0 0 0
8 2008 9 5479533823 5479533823 0 0 0 0
9 2008 10 5679440782 5679440782 0 0 0 0
10 2008 11 5415832071 5415832071 0 0 0 0
11 2008 12 5211708451 5211708451 0 0 0 0
12 2009 1 5802681551 5802681551 0 0 0 0
13 2009 2 5547320860 5547320860 0 0 0 0
14 2009 3 6295159057 6295159057 0 0 0 0
15 2009 4 5988817321 5988817321 0 0 0 0
16 2009 5 6267516733 6267516733 0 0 0 0
17 2009 6 5818924182 5818924182 0 0 0 0
18 2009 7 5801646978 5801646978 0 0 0 0
19 2009 8 5790850384 5790850384 0 0 0 0
20 2009 9 4057515768 4057515768 0 0 0 0
21 2009 10 6016107147 6016107147 0 0 0 0
22 2009 11 5768486910 5768486910 0 0 0 0
23 2009 12 5426505977 5426505977 0 0 0 0
24 2010 1 5703465285 5703465285 0 0 0 0

Step 3: Analysis

Now, we will produce a sample visualization of the Engligh Wikipedia traffic data as a time series graph tracking three traffic metrics: mobile traffic, desktop traffic, and all traffic (mobile + desktop).

Visualization Tools
To generate this visualization in the cell below, the following python libraries were used: matplotlib, seaborn, and pandas.

Data
While we could have read data from the CSV file, we used data from the combined DataFrame for the y values since df_final was already created in an earlier cell. For the x-axis values, we could have pulled the year and month from the CSV file or df_final but it was easiest to generate a date range with pandas, see the dates variable.

import matplotlib.pyplot as plt
import pandas as pd
import seaborn

"""
:param param1: this is a first param
:param param2: this is a second param
:returns: this is a description of what is returned
:raises keyError: raises an exception
"""
# Generate values for x-axis.
dates = pd.date_range('2008-01', '2017-10', freq='M')

# Values to be plotted.
x = dates
# Values are divided by 1,000,000 to make y-axis readable.
y1 = df_final["pagecount_all_views"]/1000000
y2 = df_final["pagecount_desktop_views"]/1000000
y3 = df_final["pagecount_mobile_views"]/1000000
y4 = df_final["pageview_all_views"]/1000000
y5 = df_final["pageview_desktop_views"]/1000000
y6 = df_final["pageview_mobile_views"]/1000000

# Create a new figure with appropriate dimensions.
fig = plt.figure(figsize=(11, 8))

# Show grid
plt.grid(True)

# Plot each data series from DataFrame.
plt.plot(x, y1, label = "Total", color = "seagreen",
         alpha = 0.8, linewidth = 3)
plt.plot(x, y2, label = "Main Site", color = "dodgerblue",
         alpha = 0.8, linewidth = 2)
plt.plot(x, y3, label = "Mobile", color = "sienna")
plt.plot(x, y4, linestyle = "--", label = "Total",
         color = "seagreen", alpha = 0.8, linewidth = 3)
plt.plot(x, y5, "--", label = "Main Site",
         color = "dodgerblue", alpha = 0.8, linewidth = 2)
plt.plot(x, y6, "--", label = "Mobile", color = "sienna")

plt.legend(loc=2)
plt.xlabel("Time")
plt.ylabel("Wikipedia Page Views (million)")
plt.title("Web Traffic on English Wikipedia Pages from 2008-2017")

# Display plot
plt.show()

# Save plot to file
fig.savefig("WikipediaDataPlot.png")
'\n:param param1: this is a first param\n:param param2: this is a second param\n:returns: this is a description of what is returned\n:raises keyError: raises an exception\n'
[<matplotlib.lines.Line2D at 0x7f56f974d1d0>]
[<matplotlib.lines.Line2D at 0x7f56e67f0c88>]
[<matplotlib.lines.Line2D at 0x7f56e60c1e48>]
[<matplotlib.lines.Line2D at 0x7f56e6051390>]
[<matplotlib.lines.Line2D at 0x7f56e6051f60>]
[<matplotlib.lines.Line2D at 0x7f56e6051c50>]
<matplotlib.legend.Legend at 0x7f56e6068668>
Text(0.5,0,'Time')
Text(0,0.5,'Wikipedia Page Views (million)')
Text(0.5,1,'Web Traffic on English Wikipedia Pages from 2008-2017')