pandas primera parte

parent 6991deac
......@@ -812,7 +812,11 @@
"cell_type": "markdown",
"metadata": {},
"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 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
......@@ -850,47 +854,47 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 0.994272\n",
"b 0.530519\n",
"c 1.162452\n",
"d -0.981436\n",
"e -1.283798\n",
"dtype: float64"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.series.Series'>\n",
"Campeche -0.582736\n",
"b -0.295072\n",
"a -1.100532\n",
"d -2.259605\n",
"e 0.848816\n",
"dtype: float64\n"
]
}
],
"source": [
"s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])\n",
"s"
"s = pd.Series(np.random.randn(5), index=['Campeche', 'b', 'a', 'd', 'e'])\n",
"s\n",
"print(type(s))\n",
"print(s)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2.042498\n",
"1 -0.964070\n",
"2 -0.687132\n",
"3 0.623300\n",
"4 1.366322\n",
"0 1.373283\n",
"1 -0.036890\n",
"2 -0.349894\n",
"3 -0.344340\n",
"4 1.142898\n",
"dtype: float64"
]
},
"execution_count": 46,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
......@@ -901,19 +905,19 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 0\n",
"b 1\n",
"a 0\n",
"c 2\n",
"dtype: int64"
]
},
"execution_count": 47,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
......@@ -925,7 +929,7 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 16,
"metadata": {},
"outputs": [
{
......@@ -938,7 +942,7 @@
"dtype: float64"
]
},
"execution_count": 48,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
......@@ -957,118 +961,131 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"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": {},
"output_type": "execute_result"
}
],
"source": [
"s[0]"
"s[:3]"
]
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 0.994272\n",
"b 0.530519\n",
"c 1.162452\n",
"dtype: float64"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"Campeche -0.582736\n",
"b -0.295072\n",
"a -1.100532\n",
"d -2.259605\n",
"e 0.848816\n",
"dtype: float64\n",
"-0.5827355449353806\n",
"-0.5827355449353806\n"
]
}
],
"source": [
"s[:3]"
"s[0]\n",
"temperatura_solsticio=s\n",
"print(s)\n",
"print(s[0])\n",
"print(temperatura_solsticio['Campeche'])"
]
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 0.994272\n",
"b 0.530519\n",
"c 1.162452\n",
"dtype: float64"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.series.Series'>\n",
"Campeche -0.582736\n",
"b -0.295072\n",
"e 0.848816\n",
"dtype: float64\n"
]
}
],
"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",
"execution_count": 56,
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a 1.988544\n",
"b 1.061037\n",
"c 2.324904\n",
"d -1.962872\n",
"e -2.567597\n",
"dtype: float64"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"Campeche -1.165471\n",
"b -0.590144\n",
"a -2.201063\n",
"d -4.519209\n",
"e 1.697633\n",
"dtype: float64\n"
]
}
],
"source": [
"s*2"
"serie_doble=s*2\n",
"print(serie_doble)"
]
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"a True\n",
"b False\n",
"c True\n",
"d False\n",
"e False\n",
"dtype: bool"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"median -0.5827355449353806\n",
"s Campeche -0.582736\n",
"b -0.295072\n",
"a -1.100532\n",
"d -2.259605\n",
"e 0.848816\n",
"dtype: float64\n",
"Campeche False\n",
"b True\n",
"a False\n",
"d False\n",
"e True\n",
"dtype: bool\n"
]
}
],
"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 @@
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
......@@ -1110,7 +1127,7 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": 33,
"metadata": {},
"outputs": [
{
......@@ -1119,7 +1136,7 @@
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
]
},
"execution_count": 60,
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1130,7 +1147,7 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": 34,
"metadata": {},
"outputs": [
{
......@@ -1149,7 +1166,7 @@
"dtype: int64"
]
},
"execution_count": 62,
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
......@@ -1180,32 +1197,46 @@
},
{
"cell_type": "code",
"execution_count": 76,
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"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"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"0 0\n",
"1 1\n",
"2 2\n",
"3 3\n",
"4 4\n",
"5 5\n",
"dtype: int64\n",
"4 4\n",
"5 5\n",
"6 6\n",
"7 7\n",
"8 8\n",
"9 9\n",
"dtype: int64\n",
"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": [
"(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