Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -29,10 +29,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]\n"
]
}
],
"source": [
"lst = [i for i in range(51)]\n",
"print(lst)"
]
},
{
"cell_type": "markdown",
Expand All @@ -43,10 +54,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200]\n"
]
}
],
"source": [
"lst = [i for i in range(201)if i %2 ==0]\n",
"print(lst)"
]
},
{
"cell_type": "markdown",
Expand All @@ -57,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -75,10 +97,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.84062117, 0.48006452, 0.7876326, 0.77109654, 0.44409793, 0.09014516, 0.81835917, 0.87645456, 0.7066597, 0.09610873, 0.41247947, 0.57433389, 0.29960807, 0.42315023, 0.34452557, 0.4751035, 0.17003563, 0.46843998, 0.92796258, 0.69814654, 0.41290051, 0.19561071, 0.16284783, 0.97016248, 0.71725408, 0.87702738, 0.31244595, 0.76615487, 0.20754036, 0.57871812, 0.07214068, 0.40356048, 0.12149553, 0.53222417, 0.9976855, 0.12536346, 0.80930099, 0.50962849, 0.94555126, 0.33364763]\n"
]
}
],
"source": [
"list_mat = [number for n in a for number in n]\n",
"print (list_mat)"
]
},
{
"cell_type": "markdown",
Expand All @@ -89,10 +122,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.84062117, 0.7876326, 0.77109654, 0.81835917, 0.87645456, 0.7066597, 0.57433389, 0.92796258, 0.69814654, 0.97016248, 0.71725408, 0.87702738, 0.76615487, 0.57871812, 0.53222417, 0.9976855, 0.80930099, 0.50962849, 0.94555126]\n"
]
}
],
"source": [
"list_mat_0_5 = [number for n in a for number in n if number >=0.5]\n",
"print (list_mat_0_5)\n",
"\n",
"#Qué pasa si quiero meter un else"
]
},
{
"cell_type": "markdown",
Expand All @@ -103,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -125,10 +171,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.55867166, 0.06210792, 0.08147297, 0.82579068, 0.91512478, 0.06833034, 0.05440634, 0.65857693, 0.30296619, 0.06769833, 0.96031863, 0.51293743, 0.09143215, 0.71893382, 0.45850679, 0.58256464, 0.59005654, 0.56266457, 0.71600294, 0.87392666, 0.11434044, 0.8694668, 0.65669313, 0.10708681, 0.07529684, 0.46470767, 0.47984544, 0.65368638, 0.14901286, 0.23760688]\n"
]
}
],
"source": [
"list_mat6 = [number for list1 in b for list2 in list1 for number in list2]\n",
"print(list_mat6)"
]
},
{
"cell_type": "markdown",
Expand All @@ -139,10 +196,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.48006452, 0.44409793, 0.09014516, 0.09610873, 0.41247947, 0.29960807, 0.42315023, 0.34452557, 0.4751035, 0.17003563, 0.46843998, 0.41290051, 0.19561071, 0.16284783, 0.31244595, 0.20754036, 0.07214068, 0.40356048, 0.12149553, 0.12536346, 0.33364763]\n"
]
}
],
"source": [
"list_mate = [number for n in a for number in n if number <=0.5]\n",
"print (list_mate)\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -153,10 +221,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0 1 2 3 4 5 6 \\\n",
"0 0.734751 0.195362 0.734309 0.598184 0.763433 0.263434 0.868066 \n",
"1 0.772607 0.445391 0.249642 0.787922 0.598583 0.827238 0.624126 \n",
"2 0.226428 0.268764 0.694262 0.622335 0.063843 0.122683 0.815625 \n",
"3 0.362748 0.495430 0.113876 0.594149 0.612522 0.625204 0.864050 \n",
"4 0.033415 0.340433 0.464971 0.363737 0.025815 0.434129 0.415163 \n",
"\n",
" 7 8 9 10 11 12 13 \\\n",
"0 0.058092 0.753502 0.587513 0.311608 0.178356 0.182922 0.147631 \n",
"1 0.601524 0.688753 0.338870 0.081595 0.471474 0.267443 0.453351 \n",
"2 0.584542 0.032594 0.589775 0.764350 0.650973 0.565705 0.691784 \n",
"3 0.260279 0.528873 0.168043 0.715929 0.677014 0.175735 0.632370 \n",
"4 0.892210 0.381701 0.415264 0.790801 0.696930 0.819751 0.944029 \n",
"\n",
" 14 15 16 17 18 19 \n",
"0 0.391188 0.816049 0.749068 0.293260 0.937828 0.880858 \n",
"1 0.800716 0.045749 0.683793 0.389789 0.016787 0.503695 \n",
"2 0.265223 0.739031 0.560394 0.334802 0.517694 0.646110 \n",
"3 0.926715 0.085675 0.120525 0.141746 0.771144 0.489660 \n",
"4 0.869965 0.041723 0.819140 0.676051 0.109349 0.872947 \n"
]
}
],
"source": [
"rutas=['../data/sample_file_0.txt']\n",
"dfs=[pd.read_csv(ruta) for ruta in rutas]\n",
"data=pd.concat(dfs)\n",
"print(data)"
]
},
{
"cell_type": "markdown",
Expand All @@ -167,10 +267,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 54,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0 1 2 3 4 5 6 \\\n",
"0 0.734751 0.195362 0.734309 0.598184 0.763433 0.263434 0.868066 \n",
"1 0.772607 0.445391 0.249642 0.787922 0.598583 0.827238 0.624126 \n",
"2 0.226428 0.268764 0.694262 0.622335 0.063843 0.122683 0.815625 \n",
"3 0.362748 0.495430 0.113876 0.594149 0.612522 0.625204 0.864050 \n",
"4 0.033415 0.340433 0.464971 0.363737 0.025815 0.434129 0.415163 \n",
"\n",
" 7 8 9 10 11 12 13 \\\n",
"0 0.058092 0.753502 0.587513 0.311608 0.178356 0.182922 0.147631 \n",
"1 0.601524 0.688753 0.338870 0.081595 0.471474 0.267443 0.453351 \n",
"2 0.584542 0.032594 0.589775 0.764350 0.650973 0.565705 0.691784 \n",
"3 0.260279 0.528873 0.168043 0.715929 0.677014 0.175735 0.632370 \n",
"4 0.892210 0.381701 0.415264 0.790801 0.696930 0.819751 0.944029 \n",
"\n",
" 14 15 16 17 18 19 \n",
"0 0.391188 0.816049 0.749068 0.293260 0.937828 0.880858 \n",
"1 0.800716 0.045749 0.683793 0.389789 0.016787 0.503695 \n",
"2 0.265223 0.739031 0.560394 0.334802 0.517694 0.646110 \n",
"3 0.926715 0.085675 0.120525 0.141746 0.771144 0.489660 \n",
"4 0.869965 0.041723 0.819140 0.676051 0.109349 0.872947 \n"
]
}
],
"source": [
"dfs=[pd.read_csv(ruta) for ruta in rutas]\n",
"data = pd.concat(dfs)\n",
"columns =data.head(10)\n",
"print(columns)\n",
"\n",
"#aiuda"
]
},
{
"cell_type": "markdown",
Expand All @@ -179,6 +313,29 @@
"### 8. Use a list comprehension to select and print the column numbers for columns from the data set whose median is less than 0.48."
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['3', '4', '6', '7', '8', '10', '11', '13', '14', '16', '18', '19']\n"
]
}
],
"source": [
"median = [column for column, values in data.items() if values.median() >= 0.48]\n",
"print(median)\n",
"\n",
"#medians = data.median\n",
"#print(medians)\n",
"\n",
"#cómo podría ahí meter un if"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -195,10 +352,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 69,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-69-61425f744d70>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-69-61425f744d70>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m dfs[20]= [19 if s<0.1]\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"dfs[20]= [19 if s<0.1]\n",
"print(dfs)\n",
"\n",
"#¿Podemos checarlo en clase? "
]
},
{
"cell_type": "markdown",
Expand All @@ -209,10 +380,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 66,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.7726065618884856, 0.7879222598307901, 0.7634334207035142, 0.8272382506031565, 0.8680663549990865, 0.8156248348531779, 0.8640498341918672, 0.8922104131249807, 0.7535023641545986, 0.7643495353716243, 0.7908008486938785, 0.8197511267505602, 0.944028613970866, 0.8007161479739965, 0.9267149333179154, 0.8699647196644326, 0.8160493911980281, 0.8191396818327873, 0.93782845947314, 0.7711443458405843, 0.8808575048234396, 0.8729470926088846]\n"
]
}
],
"source": [
"data_range = [value for column, values in data.items() for value in values if value >= 0.7 and value >= 0.75]\n",
"print(data_range)"
]
}
],
"metadata": {
Expand All @@ -231,7 +413,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion lab-list-comprehensions/your-code/Learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Loading