Skip to content
Open
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
215 changes: 182 additions & 33 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -29,10 +29,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[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": [
"int_1_50 = [number for number in range(1,51)]\n",
"print(int_1_50)"
]
},
{
"cell_type": "markdown",
Expand All @@ -43,10 +54,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[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]\n"
]
}
],
"source": [
"even_2_200 = [number for number in range(2,200) if number % 2 == 0]\n",
"print(even_2_200)"
]
},
{
"cell_type": "markdown",
Expand All @@ -57,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -75,10 +97,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 35,
"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": [
"#for sublist in a:\n",
"# for number in sublist:\n",
"# new_a.append(number)\n",
"\n",
"new_a = [number for sublist in a for number in sublist]\n",
"print(new_a)"
]
},
{
"cell_type": "markdown",
Expand All @@ -89,10 +126,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"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": [
"new_a2 = [number for sublist in a for number in sublist if number >= 0.5]\n",
"print(new_list2)"
]
},
{
"cell_type": "markdown",
Expand All @@ -103,7 +151,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -125,10 +173,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 42,
"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": [
"\n",
"new_b = [number for layer in b for sublist in layer for number in sublist]\n",
"print(new_b)\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -139,10 +199,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.08147297, 0.06833034, 0.30296619, 0.45850679, 0.11434044, 0.10708681, 0.47984544, 0.23760688]\n"
]
}
],
"source": [
"new_b2 = [sublist[-1] for layer in b for sublist in layer if sublist[-1] <= 0.5]\n",
"print(new_b2)\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -153,10 +224,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"sample_file_0.csv\n",
"sample_file_1.csv\n",
"sample_file_2.csv\n",
"sample_file_3.csv\n",
"sample_file_4.csv\n",
"sample_file_5.csv\n",
"sample_file_6.csv\n",
"sample_file_7.csv\n",
"sample_file_8.csv\n",
"sample_file_9.csv\n"
]
}
],
"source": [
"dir = r'C:\\Users\\guada\\OneDrive\\Documents\\Ironhack\\Week 1\\day02\\lab-list-comprehensions\\data' #define the directory in my computer\n",
"\n",
"csv_files = [filename for filename in os.listdir(dir) if filename[-4:]=='.csv'] #create the list of csv files (the ones with name ending in .csv)\n",
"\n",
"for file in csv_files:\n",
" print(file)"
]
},
{
"cell_type": "markdown",
Expand All @@ -167,10 +262,58 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 48,
"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",
"0 0.276827 0.260054 0.942397 0.113187 0.781355 0.475740 0.152061 \n",
"1 0.995885 0.158381 0.244274 0.962163 0.651900 0.930665 0.577190 \n",
"2 0.641917 0.821055 0.392437 0.782617 0.510762 0.428320 0.017324 \n",
"3 0.806532 0.569258 0.148175 0.809987 0.459632 0.735762 0.730664 \n",
"4 0.311185 0.501165 0.365979 0.782807 0.776795 0.797199 0.791946 \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",
"0 0.250324 0.147078 0.162984 0.977025 0.509619 0.593212 0.911839 \n",
"1 0.087914 0.960261 0.580840 0.194616 0.661459 0.674085 0.049326 \n",
"2 0.680720 0.340412 0.462513 0.785776 0.251949 0.032847 0.995700 \n",
"3 0.934502 0.080322 0.763502 0.398504 0.027637 0.409665 0.942846 \n",
"4 0.847157 0.771811 0.233944 0.522344 0.053030 0.208551 0.824354 \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",
"0 0.257645 0.386457 0.696932 0.069162 0.952291 0.286542 \n",
"1 0.785803 0.315645 0.495355 0.232135 0.549324 0.572232 \n",
"2 0.816563 0.735692 0.435998 0.430411 0.531757 0.489528 \n",
"3 0.133256 0.157158 0.929446 0.402791 0.685976 0.246594 \n",
"4 0.588567 0.604341 0.232964 0.229109 0.022881 0.479022 \n"
]
}
],
"source": [
"data_frames = [pd.read_csv(os.path.join(dir, file)) for file in os.listdir(dir) if file[-4:]=='.csv'] #read the path for each .csv file in the directory\n",
"combined_data_frame = pd.concat(data_frames) #combine them into a single data frame using concat\n",
"print(combined_data_frame.head(10)) #display the top 10 rows of the combined data frame\n",
"\n",
"#I'm not even sure if this is OK but I will revisit when we cove this materials "
]
},
{
"cell_type": "markdown",
Expand All @@ -184,7 +327,9 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"#will come back to this"
]
},
{
"cell_type": "markdown",
Expand All @@ -198,7 +343,9 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"#will come back to this"
]
},
{
"cell_type": "markdown",
Expand All @@ -212,12 +359,14 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"#will come back to this"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -231,9 +380,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}