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
167 changes: 135 additions & 32 deletions lab-list-comprehensions/your-code/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 85,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import numpy as np\n",
"import pandas as pd"
"import pandas as pd\n",
"from operator import itemgetter\n",
"import os\n",
"import glob"
]
},
{
Expand All @@ -29,10 +32,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"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": [
"consecutive_integers = list(map(lambda x:x,range(1,51)))\n",
"print(consecutive_integers)"
]
},
{
"cell_type": "markdown",
Expand All @@ -43,10 +55,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"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, 200]\n"
}
],
"source": [
"even_numbers = list(map(lambda x:x*2,range(1,101)))\n",
"print(even_numbers)"
]
},
{
"cell_type": "markdown",
Expand All @@ -57,7 +78,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -75,10 +96,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "[[0.84062117, 0.48006452, 0.7876326, 0.77109654],\n [0.44409793, 0.09014516, 0.81835917, 0.87645456],\n [0.7066597, 0.09610873, 0.41247947, 0.57433389],\n [0.29960807, 0.42315023, 0.34452557, 0.4751035],\n [0.17003563, 0.46843998, 0.92796258, 0.69814654],\n [0.41290051, 0.19561071, 0.16284783, 0.97016248],\n [0.71725408, 0.87702738, 0.31244595, 0.76615487],\n [0.20754036, 0.57871812, 0.07214068, 0.40356048],\n [0.12149553, 0.53222417, 0.9976855, 0.12536346],\n [0.80930099, 0.50962849, 0.94555126, 0.33364763]]"
},
"metadata": {},
"execution_count": 29
}
],
"source": [
"a.tolist()"
]
},
{
"cell_type": "markdown",
Expand All @@ -89,10 +121,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "array([0.84062117, 0.7876326 , 0.77109654, 0.81835917, 0.87645456,\n 0.7066597 , 0.57433389, 0.92796258, 0.69814654, 0.97016248,\n 0.71725408, 0.87702738, 0.76615487, 0.57871812, 0.53222417,\n 0.9976855 , 0.80930099, 0.50962849, 0.94555126])"
},
"metadata": {},
"execution_count": 28
}
],
"source": [
"a[a>=0.5]\n",
" "
]
},
{
"cell_type": "markdown",
Expand All @@ -103,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -125,10 +169,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 58,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"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": [
"b_list = b.tolist()\n",
"print(b_list)"
]
},
{
"cell_type": "markdown",
Expand All @@ -139,10 +192,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 79,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "[0.06833034, 0.10708681, 0.23760688]\n"
}
],
"source": [
"def Extract(b): \n",
" return [item[1][-1] for item in b]\n",
"\n",
"list_value = list(Extract(b))\n",
"last_value = []\n",
"\n",
"for i in list_value:\n",
" if i <= 0.5:\n",
" last_value.append(i)\n",
"print(last_value)"
]
},
{
"cell_type": "markdown",
Expand All @@ -153,10 +223,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 83,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "['sample_file_1.csv', 'sample_file_0.csv', 'sample_file_2.csv', 'sample_file_3.csv', 'sample_file_7.csv', 'sample_file_6.csv', 'sample_file_4.csv', 'sample_file_5.csv', 'sample_file_8.csv', 'sample_file_9.csv']\n"
}
],
"source": [
"files = [f for f in os.listdir('/Users/alejandropalacios/Desktop/Ironhack/Data Analytics Bootcamp/Labs/Lab-list-comprehension/Lab-list-comprehension/lab-list-comprehensions/data') if f.endswith('.csv')]\n",
"\n",
"print(files)"
]
},
{
"cell_type": "markdown",
Expand All @@ -167,10 +247,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 93,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": " 0 1 2 3 4 5 6 \\\n0 0.215190 0.155352 0.160848 0.807736 0.363587 0.899832 0.146754 \n1 0.895544 0.955196 0.089925 0.827555 0.089071 0.642883 0.996052 \n2 0.413752 0.693052 0.789796 0.929164 0.536191 0.439769 0.773474 \n3 0.728001 0.348156 0.935787 0.851163 0.444573 0.715080 0.988408 \n4 0.134942 0.875931 0.273505 0.207588 0.080696 0.717396 0.033930 \n\n 7 8 9 10 11 12 13 \\\n0 0.094802 0.705133 0.882762 0.773320 0.687745 0.016789 0.340725 \n1 0.879020 0.421837 0.412141 0.858513 0.217091 0.176157 0.551236 \n2 0.982074 0.876955 0.633154 0.279005 0.483317 0.908288 0.756172 \n3 0.210332 0.732133 0.892383 0.216893 0.367595 0.846208 0.240111 \n4 0.646837 0.888722 0.922742 0.176593 0.861333 0.389451 0.695244 \n\n 14 15 16 17 18 19 \n0 0.984182 0.985461 0.412044 0.867894 0.113432 0.349845 \n1 0.834378 0.419535 0.041431 0.602258 0.984628 0.516899 \n2 0.462130 0.289892 0.145233 0.076819 0.797836 0.197592 \n3 0.471880 0.399721 0.758196 0.665568 0.931542 0.448124 \n4 0.129955 0.364114 0.428224 0.365442 0.847818 0.588319 ",
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>0</th>\n <th>1</th>\n <th>2</th>\n <th>3</th>\n <th>4</th>\n <th>5</th>\n <th>6</th>\n <th>7</th>\n <th>8</th>\n <th>9</th>\n <th>10</th>\n <th>11</th>\n <th>12</th>\n <th>13</th>\n <th>14</th>\n <th>15</th>\n <th>16</th>\n <th>17</th>\n <th>18</th>\n <th>19</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>0.215190</td>\n <td>0.155352</td>\n <td>0.160848</td>\n <td>0.807736</td>\n <td>0.363587</td>\n <td>0.899832</td>\n <td>0.146754</td>\n <td>0.094802</td>\n <td>0.705133</td>\n <td>0.882762</td>\n <td>0.773320</td>\n <td>0.687745</td>\n <td>0.016789</td>\n <td>0.340725</td>\n <td>0.984182</td>\n <td>0.985461</td>\n <td>0.412044</td>\n <td>0.867894</td>\n <td>0.113432</td>\n <td>0.349845</td>\n </tr>\n <tr>\n <th>1</th>\n <td>0.895544</td>\n <td>0.955196</td>\n <td>0.089925</td>\n <td>0.827555</td>\n <td>0.089071</td>\n <td>0.642883</td>\n <td>0.996052</td>\n <td>0.879020</td>\n <td>0.421837</td>\n <td>0.412141</td>\n <td>0.858513</td>\n <td>0.217091</td>\n <td>0.176157</td>\n <td>0.551236</td>\n <td>0.834378</td>\n <td>0.419535</td>\n <td>0.041431</td>\n <td>0.602258</td>\n <td>0.984628</td>\n <td>0.516899</td>\n </tr>\n <tr>\n <th>2</th>\n <td>0.413752</td>\n <td>0.693052</td>\n <td>0.789796</td>\n <td>0.929164</td>\n <td>0.536191</td>\n <td>0.439769</td>\n <td>0.773474</td>\n <td>0.982074</td>\n <td>0.876955</td>\n <td>0.633154</td>\n <td>0.279005</td>\n <td>0.483317</td>\n <td>0.908288</td>\n <td>0.756172</td>\n <td>0.462130</td>\n <td>0.289892</td>\n <td>0.145233</td>\n <td>0.076819</td>\n <td>0.797836</td>\n <td>0.197592</td>\n </tr>\n <tr>\n <th>3</th>\n <td>0.728001</td>\n <td>0.348156</td>\n <td>0.935787</td>\n <td>0.851163</td>\n <td>0.444573</td>\n <td>0.715080</td>\n <td>0.988408</td>\n <td>0.210332</td>\n <td>0.732133</td>\n <td>0.892383</td>\n <td>0.216893</td>\n <td>0.367595</td>\n <td>0.846208</td>\n <td>0.240111</td>\n <td>0.471880</td>\n <td>0.399721</td>\n <td>0.758196</td>\n <td>0.665568</td>\n <td>0.931542</td>\n <td>0.448124</td>\n </tr>\n <tr>\n <th>4</th>\n <td>0.134942</td>\n <td>0.875931</td>\n <td>0.273505</td>\n <td>0.207588</td>\n <td>0.080696</td>\n <td>0.717396</td>\n <td>0.033930</td>\n <td>0.646837</td>\n <td>0.888722</td>\n <td>0.922742</td>\n <td>0.176593</td>\n <td>0.861333</td>\n <td>0.389451</td>\n <td>0.695244</td>\n <td>0.129955</td>\n <td>0.364114</td>\n <td>0.428224</td>\n <td>0.365442</td>\n <td>0.847818</td>\n <td>0.588319</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 93
}
],
"source": [
"path = r'/Users/alejandropalacios/Desktop/Ironhack/Data Analytics Bootcamp/Labs/Lab-list-comprehension/Lab-list-comprehension/lab-list-comprehensions/data'\n",
"all_files = glob.glob(path + \"/*.csv\")\n",
"\n",
"li = []\n",
"\n",
"for filename in all_files:\n",
" df = pd.read_csv(filename, index_col = None, header = 0)\n",
" li.append(df)\n",
"\n",
"frame = pd.concat(li, axis = 0, ignore_index = True)\n",
"\n",
"df.head(10)"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -217,9 +320,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3.7.6 64-bit ('anaconda3': virtualenv)",
"language": "python",
"name": "python3"
"name": "python37664bitanaconda3virtualenv0697af1ee67a458e9253591065064715"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -231,9 +334,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.7.6-final"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
}