Queer European MD passionate about IT
Browse Source

Merge pull request #15 from dataquestio/feature/srini/addmission207

Added Mission 207
Srini Kadamati 8 years ago
parent
commit
80b073ce80
1 changed files with 97 additions and 0 deletions
  1. 97 0
      Mission207Solutions.ipynb

+ 97 - 0
Mission207Solutions.ipynb

@@ -0,0 +1,97 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "collapsed": true
+   },
+   "source": [
+    "## Birth Dates In The United States\n",
+    "\n",
+    "The raw data behind the story **Some People Are Too Superstitious To Have A Baby On Friday The 13th**, which you can read [here](http://fivethirtyeight.com/features/some-people-are-too-superstitious-to-have-a-baby-on-friday-the-13th/).\n",
+    "\n",
+    "We'll be working with the data set from the Centers for Disease Control and Prevention's National National Center for Health Statistics.  The data set has the following structure:\n",
+    "\n",
+    "- `year` - Year\n",
+    "- `month` - Month\n",
+    "- `date_of_month` - Day number of the month\n",
+    "- `day_of_week` - Day of week, where 1 is Monday and 7 is Sunday\n",
+    "- `births` - Number of births"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [],
+   "source": [
+    "f = open(\"births.csv\", 'r')\n",
+    "text = f.read()\n",
+    "print(text)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [],
+   "source": [
+    "lines_list = text.split(\"\\n\")\n",
+    "lines_list"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "collapsed": false
+   },
+   "outputs": [],
+   "source": [
+    "days_counts = dict()\n",
+    "count = 0\n",
+    "\n",
+    "for line in lines_list:\n",
+    "    if count != 0:\n",
+    "        split_line = line.split(\",\")\n",
+    "        day_of_week = split_line[3]\n",
+    "        num_births = int(split_line[4])\n",
+    "        \n",
+    "        if day_of_week in days_counts:\n",
+    "            days_counts[day_of_week] = days_counts[day_of_week] + num_births\n",
+    "        else:\n",
+    "            days_counts[day_of_week] = num_births\n",
+    "    if count == 0:\n",
+    "        count += 1\n",
+    "\n",
+    "days_counts"
+   ]
+  }
+ ],
+ "metadata": {
+  "anaconda-cloud": {},
+  "kernelspec": {
+   "display_name": "Python [default]",
+   "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.4.5"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}