diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb index 0239d17..e2cf3d8 100644 --- a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -100,7 +100,7 @@ "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# After we have iterated through all elements, we will get a StopIteration Error\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# After we have iterated through all elements, we will get a StopIteration Error\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mStopIteration\u001b[0m: " ] } @@ -113,7 +113,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -146,9 +146,20 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 60, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def divisible2(iterator):\n", " # This function takes an iterable and returns the first element that is divisible by 2 and zero otherwise\n", @@ -159,7 +170,12 @@ " # Sample Output: 2\n", " \n", " # Your code here:\n", - " " + " for i in iterator:\n", + " if i%2 == 0:\n", + " return i\n", + "\n", + " \n", + "divisible2(iter([1,2,3])) " ] }, { @@ -173,7 +189,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -193,7 +209,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -224,7 +240,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -237,7 +253,35 @@ " # Sample Output: iter([0, 2, 4])\n", " \n", " # Your code here:\n", - " " + " \n", + " for i in range(n):\n", + " if i%2 == 0:\n", + " yield i\n", + " \n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "4\n" + ] + } + ], + "source": [ + "iterator = even_iterator(5)\n", + "\n", + "for i in iterator:\n", + " print(i)\n", + " \n" ] }, { @@ -253,7 +297,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -270,12 +314,100 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 5, "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthiris_type
05.13.51.40.2Iris-setosa
14.93.01.40.2Iris-setosa
24.73.21.30.2Iris-setosa
34.63.11.50.2Iris-setosa
45.03.61.40.2Iris-setosa
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width iris_type\n", + "0 5.1 3.5 1.4 0.2 Iris-setosa\n", + "1 4.9 3.0 1.4 0.2 Iris-setosa\n", + "2 4.7 3.2 1.3 0.2 Iris-setosa\n", + "3 4.6 3.1 1.5 0.2 Iris-setosa\n", + "4 5.0 3.6 1.4 0.2 Iris-setosa" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris.head()" ] }, { @@ -287,12 +419,29 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "sepal_length 5.843333\n", + "sepal_width 3.054000\n", + "petal_length 3.758667\n", + "petal_width 1.198667\n", + "dtype: float64" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris_mean = np.mean(iris)\n", + "iris_mean.head()" ] }, { @@ -304,12 +453,29 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "sepal_length 0.825301\n", + "sepal_width 0.432147\n", + "petal_length 1.758529\n", + "petal_width 0.760613\n", + "dtype: float64" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris_std_dev = np.std(iris)\n", + "iris_std_dev.head()" ] }, { @@ -321,11 +487,94 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 8, "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_width
05.13.51.40.2
14.93.01.40.2
24.73.21.30.2
34.63.11.50.2
45.03.61.40.2
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width\n", + "0 5.1 3.5 1.4 0.2\n", + "1 4.9 3.0 1.4 0.2\n", + "2 4.7 3.2 1.3 0.2\n", + "3 4.6 3.1 1.5 0.2\n", + "4 5.0 3.6 1.4 0.2" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", + "iris_numeric = iris._get_numeric_data()\n", + "iris_numeric.head()\n", "\n" ] }, @@ -338,9 +587,20 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.393701" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def cm_to_in(x):\n", " # This function takes in a numeric value in centimeters and converts it to inches\n", @@ -351,7 +611,9 @@ " # Sample Output: 0.393701\n", " \n", " # Your code here:\n", - " " + " return x*0.393701\n", + "\n", + "cm_to_in(1)" ] }, { @@ -363,12 +625,94 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 10, "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_width
02.0078751.3779540.5511810.07874
11.9291351.1811030.5511810.07874
21.8503951.2598430.5118110.07874
31.8110251.2204730.5905520.07874
41.9685051.4173240.5511810.07874
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width\n", + "0 2.007875 1.377954 0.551181 0.07874\n", + "1 1.929135 1.181103 0.551181 0.07874\n", + "2 1.850395 1.259843 0.511811 0.07874\n", + "3 1.811025 1.220473 0.590552 0.07874\n", + "4 1.968505 1.417324 0.551181 0.07874" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "iris_inch = cm_to_in(iris_numeric)\n", + "iris_inch.head()\n" ] }, { @@ -380,12 +724,93 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 11, "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_width
07.15.53.42.2
16.95.03.42.2
26.75.23.32.2
36.65.13.52.2
47.05.63.42.2
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width\n", + "0 7.1 5.5 3.4 2.2\n", + "1 6.9 5.0 3.4 2.2\n", + "2 6.7 5.2 3.3 2.2\n", + "3 6.6 5.1 3.5 2.2\n", + "4 7.0 5.6 3.4 2.2" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Define constant below:\n", - "\n", + "error = 2\n", "\n", "def add_constant(x):\n", " # This function adds a global constant to our input.\n", @@ -393,7 +818,10 @@ " # Output: numeric value\n", " \n", " # Your code here:\n", - " " + " return x+error\n", + "\n", + "iris_constant = add_constant(iris_numeric)\n", + "iris_constant.head()" ] }, { @@ -407,12 +835,34 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0 5.1\n", + "1 4.9\n", + "2 4.7\n", + "3 4.6\n", + "4 5.0\n", + " ... \n", + "145 6.7\n", + "146 6.3\n", + "147 6.5\n", + "148 6.2\n", + "149 5.9\n", + "Length: 150, dtype: float64" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "iris_numeric.apply(max, axis)" ] }, { @@ -424,12 +874,229 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 13, "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthtotal_length
05.13.51.40.26.5
14.93.01.40.26.3
24.73.21.30.26.0
34.63.11.50.26.1
45.03.61.40.26.4
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width total_length\n", + "0 5.1 3.5 1.4 0.2 6.5\n", + "1 4.9 3.0 1.4 0.2 6.3\n", + "2 4.7 3.2 1.3 0.2 6.0\n", + "3 4.6 3.1 1.5 0.2 6.1\n", + "4 5.0 3.6 1.4 0.2 6.4" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "def sum_length():\n", + " datos_sepal = [primer_nivel \n", + " for primer_nivel in iris_numeric['sepal_length']]\n", + " datos_petal = [primer_nivel \n", + " for primer_nivel in iris_numeric['petal_length']]\n", + " suma_length = [datos_sepal[i]+datos_petal[i] for i in range(len(datos_sepal))]\n", + " iris_numeric['total_length']=suma_length\n", + " iris_numeric.index=range(len(iris_numeric))\n", + " return iris_numeric.head()\n", + "\n", + "sum_length()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthtotal_lengthtotal_width
05.13.51.40.26.53.7
14.93.01.40.26.33.2
24.73.21.30.26.03.4
34.63.11.50.26.13.3
45.03.61.40.26.43.8
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width total_length \\\n", + "0 5.1 3.5 1.4 0.2 6.5 \n", + "1 4.9 3.0 1.4 0.2 6.3 \n", + "2 4.7 3.2 1.3 0.2 6.0 \n", + "3 4.6 3.1 1.5 0.2 6.1 \n", + "4 5.0 3.6 1.4 0.2 6.4 \n", + "\n", + " total_width \n", + "0 3.7 \n", + "1 3.2 \n", + "2 3.4 \n", + "3 3.3 \n", + "4 3.8 " + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def sum_width():\n", + " datos_sepal = [primer_nivel \n", + " for primer_nivel in iris_numeric['sepal_width']]\n", + " datos_petal = [primer_nivel \n", + " for primer_nivel in iris_numeric['petal_width']]\n", + " suma_width = [datos_sepal[i]+datos_petal[i] for i in range(len(datos_sepal))]\n", + " iris_numeric['total_width']=suma_width\n", + " iris_numeric.index=range(len(iris_numeric))\n", + " return iris_numeric.head()\n", + "\n", + "sum_width()" ] }, { @@ -456,7 +1123,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 0239d17..e2cf3d8 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -100,7 +100,7 @@ "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# After we have iterated through all elements, we will get a StopIteration Error\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# After we have iterated through all elements, we will get a StopIteration Error\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mStopIteration\u001b[0m: " ] } @@ -113,7 +113,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -146,9 +146,20 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 60, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def divisible2(iterator):\n", " # This function takes an iterable and returns the first element that is divisible by 2 and zero otherwise\n", @@ -159,7 +170,12 @@ " # Sample Output: 2\n", " \n", " # Your code here:\n", - " " + " for i in iterator:\n", + " if i%2 == 0:\n", + " return i\n", + "\n", + " \n", + "divisible2(iter([1,2,3])) " ] }, { @@ -173,7 +189,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -193,7 +209,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -224,7 +240,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -237,7 +253,35 @@ " # Sample Output: iter([0, 2, 4])\n", " \n", " # Your code here:\n", - " " + " \n", + " for i in range(n):\n", + " if i%2 == 0:\n", + " yield i\n", + " \n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "2\n", + "4\n" + ] + } + ], + "source": [ + "iterator = even_iterator(5)\n", + "\n", + "for i in iterator:\n", + " print(i)\n", + " \n" ] }, { @@ -253,7 +297,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -270,12 +314,100 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 5, "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthiris_type
05.13.51.40.2Iris-setosa
14.93.01.40.2Iris-setosa
24.73.21.30.2Iris-setosa
34.63.11.50.2Iris-setosa
45.03.61.40.2Iris-setosa
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width iris_type\n", + "0 5.1 3.5 1.4 0.2 Iris-setosa\n", + "1 4.9 3.0 1.4 0.2 Iris-setosa\n", + "2 4.7 3.2 1.3 0.2 Iris-setosa\n", + "3 4.6 3.1 1.5 0.2 Iris-setosa\n", + "4 5.0 3.6 1.4 0.2 Iris-setosa" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris.head()" ] }, { @@ -287,12 +419,29 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "sepal_length 5.843333\n", + "sepal_width 3.054000\n", + "petal_length 3.758667\n", + "petal_width 1.198667\n", + "dtype: float64" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris_mean = np.mean(iris)\n", + "iris_mean.head()" ] }, { @@ -304,12 +453,29 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "sepal_length 0.825301\n", + "sepal_width 0.432147\n", + "petal_length 1.758529\n", + "petal_width 0.760613\n", + "dtype: float64" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris_std_dev = np.std(iris)\n", + "iris_std_dev.head()" ] }, { @@ -321,11 +487,94 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 8, "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_width
05.13.51.40.2
14.93.01.40.2
24.73.21.30.2
34.63.11.50.2
45.03.61.40.2
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width\n", + "0 5.1 3.5 1.4 0.2\n", + "1 4.9 3.0 1.4 0.2\n", + "2 4.7 3.2 1.3 0.2\n", + "3 4.6 3.1 1.5 0.2\n", + "4 5.0 3.6 1.4 0.2" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", + "iris_numeric = iris._get_numeric_data()\n", + "iris_numeric.head()\n", "\n" ] }, @@ -338,9 +587,20 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.393701" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def cm_to_in(x):\n", " # This function takes in a numeric value in centimeters and converts it to inches\n", @@ -351,7 +611,9 @@ " # Sample Output: 0.393701\n", " \n", " # Your code here:\n", - " " + " return x*0.393701\n", + "\n", + "cm_to_in(1)" ] }, { @@ -363,12 +625,94 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 10, "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_width
02.0078751.3779540.5511810.07874
11.9291351.1811030.5511810.07874
21.8503951.2598430.5118110.07874
31.8110251.2204730.5905520.07874
41.9685051.4173240.5511810.07874
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width\n", + "0 2.007875 1.377954 0.551181 0.07874\n", + "1 1.929135 1.181103 0.551181 0.07874\n", + "2 1.850395 1.259843 0.511811 0.07874\n", + "3 1.811025 1.220473 0.590552 0.07874\n", + "4 1.968505 1.417324 0.551181 0.07874" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "iris_inch = cm_to_in(iris_numeric)\n", + "iris_inch.head()\n" ] }, { @@ -380,12 +724,93 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 11, "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_width
07.15.53.42.2
16.95.03.42.2
26.75.23.32.2
36.65.13.52.2
47.05.63.42.2
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width\n", + "0 7.1 5.5 3.4 2.2\n", + "1 6.9 5.0 3.4 2.2\n", + "2 6.7 5.2 3.3 2.2\n", + "3 6.6 5.1 3.5 2.2\n", + "4 7.0 5.6 3.4 2.2" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Define constant below:\n", - "\n", + "error = 2\n", "\n", "def add_constant(x):\n", " # This function adds a global constant to our input.\n", @@ -393,7 +818,10 @@ " # Output: numeric value\n", " \n", " # Your code here:\n", - " " + " return x+error\n", + "\n", + "iris_constant = add_constant(iris_numeric)\n", + "iris_constant.head()" ] }, { @@ -407,12 +835,34 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0 5.1\n", + "1 4.9\n", + "2 4.7\n", + "3 4.6\n", + "4 5.0\n", + " ... \n", + "145 6.7\n", + "146 6.3\n", + "147 6.5\n", + "148 6.2\n", + "149 5.9\n", + "Length: 150, dtype: float64" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "iris_numeric.apply(max, axis)" ] }, { @@ -424,12 +874,229 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 13, "metadata": {}, - "outputs": [], + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthtotal_length
05.13.51.40.26.5
14.93.01.40.26.3
24.73.21.30.26.0
34.63.11.50.26.1
45.03.61.40.26.4
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width total_length\n", + "0 5.1 3.5 1.4 0.2 6.5\n", + "1 4.9 3.0 1.4 0.2 6.3\n", + "2 4.7 3.2 1.3 0.2 6.0\n", + "3 4.6 3.1 1.5 0.2 6.1\n", + "4 5.0 3.6 1.4 0.2 6.4" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "def sum_length():\n", + " datos_sepal = [primer_nivel \n", + " for primer_nivel in iris_numeric['sepal_length']]\n", + " datos_petal = [primer_nivel \n", + " for primer_nivel in iris_numeric['petal_length']]\n", + " suma_length = [datos_sepal[i]+datos_petal[i] for i in range(len(datos_sepal))]\n", + " iris_numeric['total_length']=suma_length\n", + " iris_numeric.index=range(len(iris_numeric))\n", + " return iris_numeric.head()\n", + "\n", + "sum_length()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthtotal_lengthtotal_width
05.13.51.40.26.53.7
14.93.01.40.26.33.2
24.73.21.30.26.03.4
34.63.11.50.26.13.3
45.03.61.40.26.43.8
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width total_length \\\n", + "0 5.1 3.5 1.4 0.2 6.5 \n", + "1 4.9 3.0 1.4 0.2 6.3 \n", + "2 4.7 3.2 1.3 0.2 6.0 \n", + "3 4.6 3.1 1.5 0.2 6.1 \n", + "4 5.0 3.6 1.4 0.2 6.4 \n", + "\n", + " total_width \n", + "0 3.7 \n", + "1 3.2 \n", + "2 3.4 \n", + "3 3.3 \n", + "4 3.8 " + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def sum_width():\n", + " datos_sepal = [primer_nivel \n", + " for primer_nivel in iris_numeric['sepal_width']]\n", + " datos_petal = [primer_nivel \n", + " for primer_nivel in iris_numeric['petal_width']]\n", + " suma_width = [datos_sepal[i]+datos_petal[i] for i in range(len(datos_sepal))]\n", + " iris_numeric['total_width']=suma_width\n", + " iris_numeric.index=range(len(iris_numeric))\n", + " return iris_numeric.head()\n", + "\n", + "sum_width()" ] }, { @@ -456,7 +1123,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.8.8" } }, "nbformat": 4,