{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Week 8: Unrest via Sparse Credit Card Data" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using matplotlib backend: TkAgg\n", "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "source": [ "%pylab\n", "%matplotlib inline\n", "import pandas as pd\n", "from pandas import ExcelWriter\n", "from pandas import ExcelFile\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from scipy import stats" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We start the analysis by importing the data. Note, we are only importing the data provided in Table 1 of the Appendix of Dong et al.1 as we are only analysing data from the references days and Day 62.\n", "\n", "**\\*\\* Double Check this with Murray \\*\\***\n", "\n", "TO DO:\n", "\\*\\* Need to test the statistical significance of the data" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "# Contains data about the number of customers during the recorded time period\n", "cust_data = pd.read_excel('edited_Dong_etal_2018_data.xlsx', sheetname='# of Customers')\n", "# Contains data about the customers' median spending amounts during the recorded time period\n", "spend_data = pd.read_excel('edited_Dong_etal_2018_data.xlsx', sheetname='Median spending amount')\n", "# Contains data about the number of transactions during the recorded time period\n", "trans_data = pd.read_excel('edited_Dong_etal_2018_data.xlsx', sheetname='# of transactions')" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", "\n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", " \n", " \n", " \n", " Distance from event center (km)\n", " \n", " \n", " \n", " \n", " Min of ref. Days\n", " \n", " \n", " \n", " \n", " Max of ref. Days\n", " \n", " \n", " \n", " \n", " Decrease on Day 62\n", " \n", " \n", "
\n", " Distance from event center (km)\n", " \n", " \n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " -0.104681\n", " \n", " \n", " \n", " \n", " -0.101477\n", " \n", " \n", " \n", " \n", " -0.375261\n", " \n", " \n", "
\n", " Min of ref. Days\n", " \n", " \n", " \n", " \n", " -0.104681\n", " \n", " \n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 0.990716\n", " \n", " \n", " \n", " \n", " 0.855398\n", " \n", " \n", "
\n", " Max of ref. Days\n", " \n", " \n", " \n", " \n", " -0.101477\n", " \n", " \n", " \n", " \n", " 0.990716\n", " \n", " \n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 0.869914\n", " \n", " \n", "
\n", " Decrease on Day 62\n", " \n", " \n", " \n", " \n", " -0.375261\n", " \n", " \n", " \n", " \n", " 0.855398\n", " \n", " \n", " \n", " \n", " 0.869914\n", " \n", " \n", " \n", " \n", " 1\n", " \n", " \n", "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cust_data.corr().style.background_gradient(cmap='Wistia')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now to plot some data..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### References\n", "1. Dong, X., Meyer, J., Shmueli, E., Bozkaya, B., & Pentland, A. (2018). Methods for quantifying effects of social unrest using credit card transaction data. EPJ Data Science, 7(1), 8. https://doi.org/10.1140/epjds/s13688-018-0136-x" ] } ], "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.5.2" } }, "nbformat": 4, "nbformat_minor": 2 }