{"cells": [{"source": ["# Ideas still to do...\n", "* Holidays distribution for each year (2012-2017)\n", "* combine holiday daya with food data\n", "* any suggestions are welcome!"], "metadata": {}, "cell_type": "markdown"}, {"source": ["# Import libraries"], "metadata": {"_uuid": "c3ebfeb453d8642010aa3a70be798e9eb0919d0e", "_cell_guid": "2ae89b29-d876-457e-a6f6-e41de3b19b1e"}, "cell_type": "markdown"}, {"source": ["import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline"], "outputs": [], "metadata": {"_uuid": "31fc4b6c86e384e2037028c26124fe34fa6a2a2d", "_cell_guid": "542b7cd8-7ca3-4ca1-9605-39b4329aef8e", "collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["# Read in data"], "metadata": {"_uuid": "6b88cad5fd1430f191c1677298e0371b2784cad0", "_cell_guid": "a9ca66c2-bf40-450c-ae00-b3c9e47b1d5b"}, "cell_type": "markdown"}, {"source": ["df = pd.read_csv(\"../input/holidays_events.csv\")"], "outputs": [], "metadata": {"_uuid": "001e6ab1f63370b695a9c2f54471d5c096a8927f", "_cell_guid": "c5d01a16-52e5-4b2e-9e56-78ce9146670a", "collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["# Meta data"], "metadata": {"_uuid": "06f38152846f60e23524591eb45850078549afc3", "_cell_guid": "2ce67d7c-2f3f-4c52-9e37-b0830eec904a"}, "cell_type": "markdown"}, {"source": ["df.info()"], "outputs": [], "metadata": {"_uuid": "6fb3269303c437b11dce10ad99ec468b0d39e316", "_cell_guid": "540f7f13-2e1a-40a1-946c-bdc12f453c37"}, "execution_count": null, "cell_type": "code"}, {"source": ["# **Holidays Types per year** graph"], "metadata": {"_uuid": "84446cf07bd639f45b1683f69869147b5edac951", "_cell_guid": "8205eca3-dffb-45ce-a832-8872ee70dac8"}, "cell_type": "markdown"}, {"source": ["## Extracting the year from 'date' column and store it in a new column\n", "\n", "..so the graph can be created"], "metadata": {"_uuid": "9d977fd3c0a3eae80d0c5f4a4f0d72f680c99861", "_cell_guid": "06833996-5eb2-4c38-96fc-74a9d2074391"}, "cell_type": "markdown"}, {"source": ["for index, row in df.iterrows():\n", "        \n", "    date = row['date']\n", "    \n", "    elements = date.split(\"-\")\n", "    year = elements[0]\n", "\n", "    df.loc[index,'year'] = year"], "outputs": [], "metadata": {"_uuid": "c57bf8a18e8dd72a358fb4c5caa29cf734ea0d1c", "_cell_guid": "e614a1b8-e498-4ed4-bd73-d241f318f6c5", "collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["df2 = df.groupby(['year', 'locale']).count().reset_index()"], "outputs": [], "metadata": {"_uuid": "0a8ff426287d95057fe0d1b9b497e64c0e8b5746", "_cell_guid": "51ce4d32-8f77-4bdc-9d5b-549d5474df2f", "collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["df3 = df2[['year','locale', 'type']]"], "outputs": [], "metadata": {"_uuid": "cd0ad809fcb238b356150db5a27c477ce79ba2cd", "_cell_guid": "7d1c2ff8-eb82-4846-a856-335acd98f38b", "collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["df3"], "outputs": [], "metadata": {"_uuid": "55ed8577df135879aefdbb6b02b3543e0ba692fd", "_cell_guid": "ab093987-4336-47a6-b118-9d3c88f64d19"}, "execution_count": null, "cell_type": "code"}, {"source": ["## Store number of holiday types in a list "], "metadata": {"_uuid": "3ff77dbcb6dbd007cb0149a5be23bb9f00a000ab", "_cell_guid": "d35792c3-743b-499a-bb6c-6762825bfa5b"}, "cell_type": "markdown"}, {"source": ["local = []\n", "national = []\n", "regional = []\n", "\n", "for index, row in df3.iterrows():\n", "    \n", "    locale = row['locale']\n", "    type_value = row['type']\n", "    \n", "    if locale == \"Local\":\n", "        local.append(type_value)\n", "    elif locale == \"National\":\n", "        national.append(type_value)\n", "    else:\n", "        regional.append(type_value)"], "outputs": [], "metadata": {"_uuid": "a43b7dbe69145d646ba6d081d040e09f73e644dd", "_cell_guid": "41fccaa9-a314-4270-9353-3c0fc4861f79", "collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["## Compose graph"], "metadata": {"_uuid": "b65894759f38af91a2c23cd4663129ae875eb93c", "_cell_guid": "7b6e2f99-e26d-4bb1-8c77-3da42f5b4407"}, "cell_type": "markdown"}, {"source": ["### Set up graph"], "metadata": {"_uuid": "f7db68a361d78131355c6ccbb4a0fac75a966baa", "_cell_guid": "1f04d0ed-86e3-459f-8537-73072a6ddcb2"}, "cell_type": "markdown"}, {"source": ["x1 = ['2012', '2013', '2014', '2015', '2016', '2017']\n", "x = [1,2,3,4,5,6]\n", "N = 6\n", "ind = np.arange(N)"], "outputs": [], "metadata": {"_uuid": "011743e50b6d455bb8fc17c6250620384d3b3ff9", "_cell_guid": "11c509e5-fce2-427c-bdf5-b4ef3c76b942", "collapsed": true}, "execution_count": null, "cell_type": "code"}, {"source": ["### Create main graph"], "metadata": {"_uuid": "ce82ef2c377332e5e256f7c8d20832a829312ff6", "_cell_guid": "0b6cfb20-725d-47b1-a02b-48c67f7ece37"}, "cell_type": "markdown"}, {"source": ["ax = plt.subplot()\n", "plt.suptitle('Number of holidays per year', fontsize=14, fontweight='bold')\n", "\n", "local = ax.bar(ind-0.2, local, width=0.2, color='b', align='center')\n", "national = ax.bar(ind, national,width=0.2, color='g', align='center')\n", "regional = ax.bar(ind+0.2, regional,width=0.2, color='r', align='center')\n", "\n", "ax.set_xticklabels(('', '2012', '2013', '2014', '2015', '2016', '2017'))\n", "\n", "ax.set_xlabel('Year')\n", "ax.set_ylabel('Number of holidays')\n", "\n", "ax.legend((local, national,  regional), ('Local', 'National', 'Regional'), loc = 'upper left', bbox_to_anchor=(1, 0.5))\n", "\n", "plt.show()"], "outputs": [], "metadata": {"_uuid": "639b6ad1db7f21c0674398e54db0ecfb630605aa", "_cell_guid": "6725e585-5292-4e76-934f-a0afcdd87143"}, "execution_count": null, "cell_type": "code"}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"file_extension": ".py", "mimetype": "text/x-python", "version": "3.6.3", "codemirror_mode": {"name": "ipython", "version": 3}, "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3"}}, "nbformat_minor": 1}