diff --git a/notebooks/process/download-distancing-data.ipynb b/notebooks/process/download-distancing-data.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..5668354c974cadf1c97acd6df1f15ecefc75e123 --- /dev/null +++ b/notebooks/process/download-distancing-data.ipynb @@ -0,0 +1,184 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import os\n", + "from io import BytesIO\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [ + "parameters" + ] + }, + "outputs": [], + "source": [ + "out_folder = \"../data/distancing-metrics/\"\n", + "PAPERMILL_OUTPUT_PATH = None" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Download Apple Mobility\n", + "\n", + "Download the Apple data. The URL for this changes every day and needs to be updated. You can get the \n", + "current URL from https://www.apple.com/covid19/mobility by looking at the link of the *All Data CSV* button." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "url = 'https://covid19-static.cdn-apple.com/covid19-mobility-data/2007HotfixDev55/v2/en-us/applemobilitytrends-2020-05-10.csv'\n", + "r = requests.get(url, allow_redirects=True)\n", + "apple_csv = r.content" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# save the result\n", + "if PAPERMILL_OUTPUT_PATH:\n", + " out_path = os.path.join(out_folder, 'mobility/apple/applemobilitytrends.csv')\n", + " with open(out_path, 'wb') as f:\n", + " f.write(apple_csv)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "apple_df = pd.read_csv(BytesIO(apple_csv))\n", + "print(len(apple_df), \"rows of data\")\n", + "apple_df.head(2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Download Google Mobility\n", + "\n", + "Download the Google data." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "url = 'https://www.gstatic.com/covid19/mobility/Global_Mobility_Report.csv'\n", + "r = requests.get(url, allow_redirects=True)\n", + "google_csv = r.content" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# save the result\n", + "if PAPERMILL_OUTPUT_PATH:\n", + " out_path = os.path.join(out_folder, 'mobility/google/Global_Mobility_Report.csv')\n", + " with open(out_path, 'wb') as f:\n", + " f.write(google_csv)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "google_df = pd.read_csv(BytesIO(google_csv))\n", + "print(len(google_df), \"rows of data\")\n", + "google_df.head(2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Download BU US State Measures\n", + "\n", + "Download the BU US State Measures spreadsheet." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "url = 'https://docs.google.com/spreadsheets/d/1zu9qEWI8PsOI_i8nI_S29HDGHlIp2lfVMsGxpQ5tvAQ/gviz/tq?tqx=out:csv'\n", + "r = requests.get(url, allow_redirects=True)\n", + "bu_csv = r.content" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# save the result\n", + "if PAPERMILL_OUTPUT_PATH:\n", + " out_path = os.path.join(out_folder, 'measures-us/bu-edu.csv')\n", + " with open(out_path, 'wb') as f:\n", + " f.write(bu_csv)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "bu_df = pd.read_csv(BytesIO(bu_csv))\n", + "print(len(bu_df), \"rows of data\")\n", + "bu_df.head(2)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}