Queer European MD passionate about IT
Browse Source

added mission 9

Srini Kadamati 8 years ago
parent
commit
c66049baea
2 changed files with 62 additions and 44 deletions
  1. 61 44
      Mission9Solutions.ipynb
  2. 1 0
      README.md

+ 61 - 44
Mission9Solutions.ipynb

@@ -11,7 +11,7 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 81,
+   "execution_count": 136,
    "metadata": {
    "metadata": {
     "collapsed": false
     "collapsed": false
    },
    },
@@ -22,7 +22,7 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 82,
+   "execution_count": 137,
    "metadata": {
    "metadata": {
     "collapsed": false
     "collapsed": false
    },
    },
@@ -42,7 +42,7 @@
        " '1994,1,9,7,7910']"
        " '1994,1,9,7,7910']"
       ]
       ]
      },
      },
-     "execution_count": 82,
+     "execution_count": 137,
      "metadata": {},
      "metadata": {},
      "output_type": "execute_result"
      "output_type": "execute_result"
     }
     }
@@ -60,23 +60,23 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 71,
+   "execution_count": 138,
    "metadata": {
    "metadata": {
     "collapsed": false
     "collapsed": false
    },
    },
    "outputs": [],
    "outputs": [],
    "source": [
    "source": [
     "def read_csv(filename):\n",
     "def read_csv(filename):\n",
-    "    data_string = open(filename).read()\n",
-    "    data_list = data_string.split(\"\\n\")[1:]\n",
-    "    final_list = list()\n",
+    "    string_data = open(filename).read()\n",
+    "    string_list = string_data.split(\"\\n\")[1:]\n",
+    "    final_list = []\n",
     "    \n",
     "    \n",
-    "    for row in data_list:\n",
-    "        row_list = row.split(\",\")\n",
-    "        int_row_list = list()\n",
-    "        for val_string in row_list:\n",
-    "            int_row_list.append(int(val_string))\n",
-    "        final_list.append(int_row_list)\n",
+    "    for row in string_list:\n",
+    "        string_fields = row.split(\",\")\n",
+    "        int_fields = []\n",
+    "        for value in string_fields:\n",
+    "            int_fields.append(int(value))\n",
+    "        final_list.append(int_fields)\n",
     "    return final_list\n",
     "    return final_list\n",
     "        \n",
     "        \n",
     "cdc_list = read_csv(\"US_births_1994-2003_CDC_NCHS.csv\")"
     "cdc_list = read_csv(\"US_births_1994-2003_CDC_NCHS.csv\")"
@@ -84,7 +84,7 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 85,
+   "execution_count": 139,
    "metadata": {
    "metadata": {
     "collapsed": false
     "collapsed": false
    },
    },
@@ -104,7 +104,7 @@
        " [1994, 1, 10, 1, 10498]]"
        " [1994, 1, 10, 1, 10498]]"
       ]
       ]
      },
      },
-     "execution_count": 85,
+     "execution_count": 139,
      "metadata": {},
      "metadata": {},
      "output_type": "execute_result"
      "output_type": "execute_result"
     }
     }
@@ -122,30 +122,46 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 73,
+   "execution_count": 140,
    "metadata": {
    "metadata": {
     "collapsed": false
     "collapsed": false
    },
    },
    "outputs": [],
    "outputs": [],
    "source": [
    "source": [
+    "def read_csv(filename):\n",
+    "    string_data = open(filename).read()\n",
+    "    string_list = string_data.split(\"\\n\")[1:]\n",
+    "    final_list = []\n",
+    "    \n",
+    "    for row in string_list:\n",
+    "        string_fields = row.split(\",\")\n",
+    "        int_fields = []\n",
+    "        for value in string_fields:\n",
+    "            int_fields.append(int(value))\n",
+    "        final_list.append(int_fields)\n",
+    "    return final_list\n",
+    "        \n",
+    "cdc_list = read_csv(\"US_births_1994-2003_CDC_NCHS.csv\")\n",
+    "\n",
+    "\n",
     "def month_births(data):\n",
     "def month_births(data):\n",
-    "    month_sums = dict()\n",
+    "    births_per_month = {}\n",
     "    \n",
     "    \n",
     "    for row in data:\n",
     "    for row in data:\n",
     "        month = row[1]\n",
     "        month = row[1]\n",
     "        births = row[4]\n",
     "        births = row[4]\n",
-    "        if month in month_sums:\n",
-    "            month_sums[month] = month_sums[month] + births\n",
+    "        if month in births_per_month:\n",
+    "            births_per_month[month] = births_per_month[month] + births\n",
     "        else:\n",
     "        else:\n",
-    "            month_sums[month] = births\n",
-    "    return month_sums\n",
+    "            births_per_month[month] = births\n",
+    "    return births_per_month\n",
     "    \n",
     "    \n",
     "cdc_month_births = month_births(cdc_list)"
     "cdc_month_births = month_births(cdc_list)"
    ]
    ]
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 74,
+   "execution_count": 141,
    "metadata": {
    "metadata": {
     "collapsed": false
     "collapsed": false
    },
    },
@@ -167,7 +183,7 @@
        " 12: 3301860}"
        " 12: 3301860}"
       ]
       ]
      },
      },
-     "execution_count": 74,
+     "execution_count": 141,
      "metadata": {},
      "metadata": {},
      "output_type": "execute_result"
      "output_type": "execute_result"
     }
     }
@@ -185,32 +201,33 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 86,
+   "execution_count": 142,
    "metadata": {
    "metadata": {
     "collapsed": true
     "collapsed": true
    },
    },
    "outputs": [],
    "outputs": [],
    "source": [
    "source": [
     "def dow_births(data):\n",
     "def dow_births(data):\n",
-    "    dow_sums = dict()\n",
+    "    births_per_dow = {}\n",
     "    \n",
     "    \n",
     "    for row in data:\n",
     "    for row in data:\n",
     "        dow = row[3]\n",
     "        dow = row[3]\n",
     "        births = row[4]\n",
     "        births = row[4]\n",
-    "        if dow in dow_sums:\n",
-    "            dow_sums[dow] = dow_sums[dow] + births\n",
+    "        if dow in births_per_dow:\n",
+    "            births_per_dow[dow] = births_per_dow[dow] + births\n",
     "        else:\n",
     "        else:\n",
-    "            dow_sums[dow] = births\n",
-    "    return dow_sums\n",
+    "            births_per_dow[dow] = births\n",
+    "    return births_per_dow\n",
     "    \n",
     "    \n",
     "cdc_dow_births = dow_births(cdc_list)"
     "cdc_dow_births = dow_births(cdc_list)"
    ]
    ]
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 87,
+   "execution_count": 143,
    "metadata": {
    "metadata": {
-    "collapsed": false
+    "collapsed": false,
+    "scrolled": true
    },
    },
    "outputs": [
    "outputs": [
     {
     {
@@ -225,7 +242,7 @@
        " 7: 4079723}"
        " 7: 4079723}"
       ]
       ]
      },
      },
-     "execution_count": 87,
+     "execution_count": 143,
      "metadata": {},
      "metadata": {},
      "output_type": "execute_result"
      "output_type": "execute_result"
     }
     }
@@ -243,17 +260,17 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 101,
+   "execution_count": 144,
    "metadata": {
    "metadata": {
     "collapsed": false
     "collapsed": false
    },
    },
    "outputs": [],
    "outputs": [],
    "source": [
    "source": [
-    "def calc_counts(data, col_num):\n",
-    "    sums_dict = dict()\n",
+    "def calc_counts(data, column):\n",
+    "    sums_dict = {}\n",
     "    \n",
     "    \n",
     "    for row in data:\n",
     "    for row in data:\n",
-    "        col_value = row[col_num]\n",
+    "        col_value = row[column]\n",
     "        births = row[4]\n",
     "        births = row[4]\n",
     "        if col_value in sums_dict:\n",
     "        if col_value in sums_dict:\n",
     "            sums_dict[col_value] = sums_dict[col_value] + births\n",
     "            sums_dict[col_value] = sums_dict[col_value] + births\n",
@@ -269,7 +286,7 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 102,
+   "execution_count": 145,
    "metadata": {
    "metadata": {
     "collapsed": false
     "collapsed": false
    },
    },
@@ -289,7 +306,7 @@
        " 2003: 4089950}"
        " 2003: 4089950}"
       ]
       ]
      },
      },
-     "execution_count": 102,
+     "execution_count": 145,
      "metadata": {},
      "metadata": {},
      "output_type": "execute_result"
      "output_type": "execute_result"
     }
     }
@@ -300,7 +317,7 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 103,
+   "execution_count": 146,
    "metadata": {
    "metadata": {
     "collapsed": false
     "collapsed": false
    },
    },
@@ -322,7 +339,7 @@
        " 12: 3301860}"
        " 12: 3301860}"
       ]
       ]
      },
      },
-     "execution_count": 103,
+     "execution_count": 146,
      "metadata": {},
      "metadata": {},
      "output_type": "execute_result"
      "output_type": "execute_result"
     }
     }
@@ -333,7 +350,7 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 104,
+   "execution_count": 147,
    "metadata": {
    "metadata": {
     "collapsed": false,
     "collapsed": false,
     "scrolled": true
     "scrolled": true
@@ -375,7 +392,7 @@
        " 31: 746696}"
        " 31: 746696}"
       ]
       ]
      },
      },
-     "execution_count": 104,
+     "execution_count": 147,
      "metadata": {},
      "metadata": {},
      "output_type": "execute_result"
      "output_type": "execute_result"
     }
     }
@@ -386,7 +403,7 @@
   },
   },
   {
   {
    "cell_type": "code",
    "cell_type": "code",
-   "execution_count": 105,
+   "execution_count": 148,
    "metadata": {
    "metadata": {
     "collapsed": false
     "collapsed": false
    },
    },
@@ -403,7 +420,7 @@
        " 7: 4079723}"
        " 7: 4079723}"
       ]
       ]
      },
      },
-     "execution_count": 105,
+     "execution_count": 148,
      "metadata": {},
      "metadata": {},
      "output_type": "execute_result"
      "output_type": "execute_result"
     }
     }

+ 1 - 0
README.md

@@ -4,6 +4,7 @@ This repository is a series of notebooks that show solutions for the [projects](
 
 
 Of course, there are always going to be multiple ways to solve any one problem, so these notebooks just show one possible solution.
 Of course, there are always going to be multiple ways to solve any one problem, so these notebooks just show one possible solution.
 
 
+- [Guided Project: Explore U.S. Births](https://github.com/dataquestio/solutions/blob/master/Mission9Solutions.ipynb)
 - [Guided Project: Customizing Data Visualizations](https://github.com/dataquestio/solutions/blob/master/Mission103Solutions.ipynb)
 - [Guided Project: Customizing Data Visualizations](https://github.com/dataquestio/solutions/blob/master/Mission103Solutions.ipynb)
 - [Guided Project: Star Wars survey](https://github.com/dataquestio/solutions/blob/master/Mission201Solution.ipynb)
 - [Guided Project: Star Wars survey](https://github.com/dataquestio/solutions/blob/master/Mission201Solution.ipynb)
 - [Guided Project: Police killings](https://github.com/dataquestio/solutions/blob/master/Mission202Solution.ipynb)
 - [Guided Project: Police killings](https://github.com/dataquestio/solutions/blob/master/Mission202Solution.ipynb)