Queer European MD passionate about IT
瀏覽代碼

Merge pull request #52 from dataquestio/update302

Replaced 304
Srini Kadamati 6 年之前
父節點
當前提交
7678ceca85
共有 1 個文件被更改,包括 24 次插入54 次删除
  1. 24 54
      Mission304Solutions.ipynb

+ 24 - 54
Mission304Solutions.ipynb

@@ -4,7 +4,7 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "# Python Intermediate: Creating a Baby Pandas Class Solutions"
+    "# Python Intermediate: Creating a SimpleFrame Class"
    ]
   },
   {
@@ -34,13 +34,11 @@
     "To preview our data, we’ll need to:\n",
     "- Be able to view the first five rows\n",
     "- Be able to view the shape of our data\n",
-    "- Be able to view the data types for each column\n",
     "\n",
     "To manipulate our data, we’ll need to: \n",
     "- Add new columns\n",
     "- Be able to apply values to columns\n",
     "- Be able to subset our data\n",
-    "- Change the data type\n",
     "\n",
     "To make calculations, we’ll need to:\n",
     "- Finding the minimum\n",
@@ -55,57 +53,45 @@
    "source": [
     "# Translating our words into objects\n",
     "\n",
-    "BabyPandas -> Class\n",
-    "\n",
-    "Load -> Method\n",
-    "\n",
-    "Data -> Attribute\n",
-    "\n",
-    "Columns -> Attribute\n",
+    "- SimpleFrame -> Class\n",
+    "- Load -> Method\n",
+    "- Data -> Attribute\n",
+    "- Columns -> Attribute\n",
     "\n",
     "## Preview\n",
     "\n",
-    "View the first five rows -> Method\n",
-    "\n",
-    "View num of rows/cols of our data -> Method\n",
-    "\n",
-    "View the data types for each column -> Method\n",
-    "\n",
+    "- View the first five rows -> Method\n",
+    "- View num of rows/cols of our data -> Method\n",
     "\n",
     "## Manipulate\n",
     "\n",
-    "Add new columns -> Method\n",
-    "\n",
-    "Apply values to columns -> Method\n",
-    "\n",
-    "subset our data -> Method\n",
-    "\n",
-    "Change the data type -> Method\n",
-    "\n",
+    "- Add new columns -> Method\n",
+    "- Apply values to columns -> Method\n",
+    "- Subset our data -> Method\n",
     "\n",
     "## Calculations\n",
     "\n",
-    "Minimum -> Method\n",
-    "\n",
-    "Maximum -> Method\n",
-    "\n",
-    "Mean -> Method\n",
-    "\n",
-    "Standard deviation -> Method"
+    "- Minimum -> Method\n",
+    "- Maximum -> Method\n",
+    "- Mean -> Method\n",
+    "- Standard deviation -> Method"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 31,
+   "execution_count": 1,
    "metadata": {},
    "outputs": [
     {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "2\n",
-      "['Despacito (Featuring Daddy Yankee)', 'Luis Fonsi', 64238]\n",
-      "['Por Fin Te Encontré', 'Cali Y El Dandee', 1993]\n"
+     "ename": "FileNotFoundError",
+     "evalue": "[Errno 2] No such file or directory: 'music_data.csv'",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+      "\u001b[0;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
+      "\u001b[0;32m<ipython-input-1-49ed6515bc96>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     95\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     96\u001b[0m \u001b[0ms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mBabyPandas\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"music_data.csv\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 97\u001b[0;31m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     98\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     99\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+      "\u001b[0;32m<ipython-input-1-49ed6515bc96>\u001b[0m in \u001b[0;36mread_data\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m     10\u001b[0m         \u001b[0mReads\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mopens\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     11\u001b[0m         '''\n\u001b[0;32m---> 12\u001b[0;31m         \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfilename\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"r\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     13\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcsv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreader\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolumns\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+      "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'music_data.csv'"
      ]
     }
    ],
@@ -130,12 +116,6 @@
     "        Displays the first five rows\n",
     "        '''\n",
     "        return self.data[:5]\n",
-    "    \n",
-    "    def info(self):\n",
-    "        types = []\n",
-    "        for value in self.data[1]:\n",
-    "            types.append(type(value))\n",
-    "        return types\n",
     "        \n",
     "    \n",
     "    def shape(self):\n",
@@ -161,14 +141,6 @@
     "        for data in self.data[1:]:\n",
     "            data[column_index] = new_value\n",
     "    \n",
-    "    def change_type(self, column_name, function):\n",
-    "        for pos, col in enumerate(self.data[0]):\n",
-    "            if col == column_name:\n",
-    "                column_index = pos\n",
-    "        \n",
-    "        for data in self.data[1:]:\n",
-    "            data[column_index] = function(data[column_index])\n",
-    "    \n",
     "    def subset(self, column_name, row_value):\n",
     "        for pos, col in enumerate(self.data[0]):\n",
     "            if col == column_name:\n",
@@ -222,11 +194,9 @@
     "s = BabyPandas(\"music_data.csv\")\n",
     "s.read_data()\n",
     "\n",
-    "s.info()\n",
     "s.shape()\n",
     "s.columns\n",
     "s.new_column('hello')\n",
-    "s.change_type('Streams',int)\n",
     "s.subset(\"Artist\",\"Shakira\")\n",
     "print(s.maximum(\"Streams\"))\n",
     "print(s.minimum(\"Streams\"))"