pandas primera parte

parent 6991deac
...@@ -812,7 +812,11 @@ ...@@ -812,7 +812,11 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 5.2.5 Utilizando la funcion anterior escribe otra que obtenga la pseduo-inversa de una matriz." "### 5.2.5 Utilizando la funcion anterior escribe otra que obtenga la pseduo-inversa de una matriz.\n",
"Def: Una matriz pseudoinversa es (At * A)^-1 * At\n",
"Nota: solo las matrices cuadradas tienen inversa\n",
"Nota: Utilice arreglos de numpy\n",
"Nota: se puede usar numpy, arreglo de arreglos y transpuestas y inversas."
] ]
}, },
{ {
...@@ -840,7 +844,7 @@ ...@@ -840,7 +844,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -850,47 +854,47 @@ ...@@ -850,47 +854,47 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 51, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"a 0.994272\n", "text": [
"b 0.530519\n", "<class 'pandas.core.series.Series'>\n",
"c 1.162452\n", "Campeche -0.582736\n",
"d -0.981436\n", "b -0.295072\n",
"e -1.283798\n", "a -1.100532\n",
"dtype: float64" "d -2.259605\n",
] "e 0.848816\n",
}, "dtype: float64\n"
"execution_count": 51, ]
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])\n", "s = pd.Series(np.random.randn(5), index=['Campeche', 'b', 'a', 'd', 'e'])\n",
"s" "s\n",
"print(type(s))\n",
"print(s)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"0 2.042498\n", "0 1.373283\n",
"1 -0.964070\n", "1 -0.036890\n",
"2 -0.687132\n", "2 -0.349894\n",
"3 0.623300\n", "3 -0.344340\n",
"4 1.366322\n", "4 1.142898\n",
"dtype: float64" "dtype: float64"
] ]
}, },
"execution_count": 46, "execution_count": 14,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -901,19 +905,19 @@ ...@@ -901,19 +905,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"a 0\n",
"b 1\n", "b 1\n",
"a 0\n",
"c 2\n", "c 2\n",
"dtype: int64" "dtype: int64"
] ]
}, },
"execution_count": 47, "execution_count": 15,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -925,7 +929,7 @@ ...@@ -925,7 +929,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": 16,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -938,7 +942,7 @@ ...@@ -938,7 +942,7 @@
"dtype: float64" "dtype: float64"
] ]
}, },
"execution_count": 48, "execution_count": 16,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -957,118 +961,131 @@ ...@@ -957,118 +961,131 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 53, "execution_count": 54,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"0.9942721192063438" "a 0.994272\n",
"b 0.530519\n",
"c 1.162452\n",
"dtype: float64"
] ]
}, },
"execution_count": 53, "execution_count": 54,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
], ],
"source": [ "source": [
"s[0]" "s[:3]"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 54, "execution_count": 19,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"a 0.994272\n", "text": [
"b 0.530519\n", "Campeche -0.582736\n",
"c 1.162452\n", "b -0.295072\n",
"dtype: float64" "a -1.100532\n",
] "d -2.259605\n",
}, "e 0.848816\n",
"execution_count": 54, "dtype: float64\n",
"metadata": {}, "-0.5827355449353806\n",
"output_type": "execute_result" "-0.5827355449353806\n"
]
} }
], ],
"source": [ "source": [
"s[:3]" "s[0]\n",
"temperatura_solsticio=s\n",
"print(s)\n",
"print(s[0])\n",
"print(temperatura_solsticio['Campeche'])"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 55, "execution_count": 21,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"a 0.994272\n", "text": [
"b 0.530519\n", "<class 'pandas.core.series.Series'>\n",
"c 1.162452\n", "Campeche -0.582736\n",
"dtype: float64" "b -0.295072\n",
] "e 0.848816\n",
}, "dtype: float64\n"
"execution_count": 55, ]
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"s[s>s.mean()]" "serie_mayor_promedio = s[s>s.mean()]\n",
"print(type(serie_mayor_promedio))\n",
"print(serie_mayor_promedio)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 56, "execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"a 1.988544\n", "text": [
"b 1.061037\n", "Campeche -1.165471\n",
"c 2.324904\n", "b -0.590144\n",
"d -1.962872\n", "a -2.201063\n",
"e -2.567597\n", "d -4.519209\n",
"dtype: float64" "e 1.697633\n",
] "dtype: float64\n"
}, ]
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"s*2" "serie_doble=s*2\n",
"print(serie_doble)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 57, "execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"a True\n", "text": [
"b False\n", "median -0.5827355449353806\n",
"c True\n", "s Campeche -0.582736\n",
"d False\n", "b -0.295072\n",
"e False\n", "a -1.100532\n",
"dtype: bool" "d -2.259605\n",
] "e 0.848816\n",
}, "dtype: float64\n",
"execution_count": 57, "Campeche False\n",
"metadata": {}, "b True\n",
"output_type": "execute_result" "a False\n",
"d False\n",
"e True\n",
"dtype: bool\n"
]
} }
], ],
"source": [ "source": [
"s>s.median()" "s>s.median()\n",
"print('median', s.median())\n",
"print('s', s)\n",
"print(s>s.median())"
] ]
}, },
{ {
...@@ -1100,7 +1117,7 @@ ...@@ -1100,7 +1117,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -1110,7 +1127,7 @@ ...@@ -1110,7 +1127,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 60, "execution_count": 33,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1119,7 +1136,7 @@ ...@@ -1119,7 +1136,7 @@
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])" "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
] ]
}, },
"execution_count": 60, "execution_count": 33,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1130,7 +1147,7 @@ ...@@ -1130,7 +1147,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 62, "execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1149,7 +1166,7 @@ ...@@ -1149,7 +1166,7 @@
"dtype: int64" "dtype: int64"
] ]
}, },
"execution_count": 62, "execution_count": 34,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1180,32 +1197,46 @@ ...@@ -1180,32 +1197,46 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 76, "execution_count": 37,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"0 NaN\n", "text": [
"1 NaN\n", "0 0\n",
"2 NaN\n", "1 1\n",
"3 NaN\n", "2 2\n",
"4 8.0\n", "3 3\n",
"5 10.0\n", "4 4\n",
"6 NaN\n", "5 5\n",
"7 NaN\n", "dtype: int64\n",
"8 NaN\n", "4 4\n",
"9 NaN\n", "5 5\n",
"dtype: float64" "6 6\n",
] "7 7\n",
}, "8 8\n",
"execution_count": 76, "9 9\n",
"metadata": {}, "dtype: int64\n",
"output_type": "execute_result" "0 NaN\n",
"1 NaN\n",
"2 NaN\n",
"3 NaN\n",
"4 8.0\n",
"5 10.0\n",
"6 NaN\n",
"7 NaN\n",
"8 NaN\n",
"9 NaN\n",
"dtype: float64\n"
]
} }
], ],
"source": [ "source": [
"(s[:6]+s[4:])" "# En series la suma es elemento por elemento pero con respecto a índices\n",
"print(s[:6])\n",
"print(s[4:])\n",
"print(s[:6]+s[4:])"
] ]
}, },
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment