diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb new file mode 100644 index 0000000..53681ae --- /dev/null +++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb @@ -0,0 +1,438 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# List Comprehensions Lab\n", + "\n", + "Complete the following set of exercises to solidify your knowledge of list comprehensions." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import numpy as np\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1. Use a list comprehension to create and print a list of consecutive integers starting with 1 and ending with 50." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "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": [ + "lista=[i for i in range(1,51)]\n", + "print (lista)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2. Use a list comprehension to create and print a list of even numbers starting with 2 and ending with 200." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "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, 200]\n" + ] + } + ], + "source": [ + "lst_even=[i for i in range (2,201,2)]\n", + "print (lst_even)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3. Use a list comprehension to create and print a list containing all elements of the 10 x 4 Numpy array below." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "a = np.array([[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]])" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "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": [ + "lista3=[j for i in a for j in i]\n", + "print (lista3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4. Add a condition to the list comprehension above so that only values greater than or equal to 0.5 are printed." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "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": [ + "lista4=[j for i in a for j in i if j >= 0.5]\n", + "print (lista4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5. Use a list comprehension to create and print a list containing all elements of the 5 x 2 x 3 Numpy array below." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "b = np.array([[[0.55867166, 0.06210792, 0.08147297],\n", + " [0.82579068, 0.91512478, 0.06833034]],\n", + "\n", + " [[0.05440634, 0.65857693, 0.30296619],\n", + " [0.06769833, 0.96031863, 0.51293743]],\n", + "\n", + " [[0.09143215, 0.71893382, 0.45850679],\n", + " [0.58256464, 0.59005654, 0.56266457]],\n", + "\n", + " [[0.71600294, 0.87392666, 0.11434044],\n", + " [0.8694668 , 0.65669313, 0.10708681]],\n", + "\n", + " [[0.07529684, 0.46470767, 0.47984544],\n", + " [0.65368638, 0.14901286, 0.23760688]]])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "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": [ + "lista5=[k for i in b for j in i for k in j]\n", + "\n", + "print (lista5)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5. Add a condition to the list comprehension above so that the last value in each subarray is printed, but only if it is less than or equal to 0.5." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "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": [ + "lista5a = [k for i in b for j in i for k in j if k == j[-1] if k <= 0.5]\n", + "\n", + "print (lista5a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 6. Use a list comprehension to select and print the names of all CSV files in the */data* directory." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['sample_file_0.csv', 'sample_file_1.csv', 'sample_file_2.csv', 'sample_file_3.csv', 'sample_file_4.csv', 'sample_file_5.csv', 'sample_file_6.csv', 'sample_file_7.csv', 'sample_file_8.csv', 'sample_file_9.csv']\n" + ] + } + ], + "source": [ + "file_list = [f for f in os.listdir('../data') if f.endswith('.csv')]\n", + "\n", + "print(file_list)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 7. Use a list comprehension and the Pandas `read_csv` and `concat` methods to read all CSV files in the */data* directory and combine them into a single data frame. Display the top 10 rows of the resulting data frame." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "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_sets = [pd.read_csv(os.path.join('../data', f)) for f in file_list]\n", + "data = pd.concat(data_sets, axis=0)\n", + "top10 = data[0:10]\n", + "\n", + "print(top10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 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": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['0', '1', '3', '4', '5', '6', '7', '8', '10', '11', '13', '15', '16', '18', '19']\n" + ] + } + ], + "source": [ + "selected_columns = [col for col in data._get_numeric_data() if data[col].median() > .48]\n", + "print(selected_columns)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 9. Use a list comprehension to add a new column (20) to the data frame whose values are the values in column 19 minus 0.1. Display the top 10 rows of the resulting data frame." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "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 ... 11 12 13 14 \\\n", + "0 0.058092 0.753502 0.587513 ... 0.178356 0.182922 0.147631 0.391188 \n", + "1 0.601524 0.688753 0.338870 ... 0.471474 0.267443 0.453351 0.800716 \n", + "2 0.584542 0.032594 0.589775 ... 0.650973 0.565705 0.691784 0.265223 \n", + "3 0.260279 0.528873 0.168043 ... 0.677014 0.175735 0.632370 0.926715 \n", + "4 0.892210 0.381701 0.415264 ... 0.696930 0.819751 0.944029 0.869965 \n", + "0 0.250324 0.147078 0.162984 ... 0.509619 0.593212 0.911839 0.257645 \n", + "1 0.087914 0.960261 0.580840 ... 0.661459 0.674085 0.049326 0.785803 \n", + "2 0.680720 0.340412 0.462513 ... 0.251949 0.032847 0.995700 0.816563 \n", + "3 0.934502 0.080322 0.763502 ... 0.027637 0.409665 0.942846 0.133256 \n", + "4 0.847157 0.771811 0.233944 ... 0.053030 0.208551 0.824354 0.588567 \n", + "\n", + " 15 16 17 18 19 20 \n", + "0 0.816049 0.749068 0.293260 0.937828 0.880858 0.780858 \n", + "1 0.045749 0.683793 0.389789 0.016787 0.503695 0.403695 \n", + "2 0.739031 0.560394 0.334802 0.517694 0.646110 0.546110 \n", + "3 0.085675 0.120525 0.141746 0.771144 0.489660 0.389660 \n", + "4 0.041723 0.819140 0.676051 0.109349 0.872947 0.772947 \n", + "0 0.386457 0.696932 0.069162 0.952291 0.286542 0.186542 \n", + "1 0.315645 0.495355 0.232135 0.549324 0.572232 0.472232 \n", + "2 0.735692 0.435998 0.430411 0.531757 0.489528 0.389528 \n", + "3 0.157158 0.929446 0.402791 0.685976 0.246594 0.146594 \n", + "4 0.604341 0.232964 0.229109 0.022881 0.479022 0.379022 \n", + "\n", + "[10 rows x 21 columns]\n" + ] + } + ], + "source": [ + "data['20']=data['19']-0.1\n", + "top10b=data[0:10]\n", + "print (top10b)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 10. Use a list comprehension to extract and print all values from the data set that are between 0.7 and 0.75." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.7347510852128797, 0.7343092314001137, 0.7490680818183477, 0.7390312927111312, 0.7159290265157912, 0.7356923324968598, 0.7357618655811269, 0.7306642125209889, 0.7033930409580709, 0.7013619954419494, 0.7396561066717461, 0.7045750112959754, 0.7383982036983279, 0.7178166705957928, 0.7088042362916818, 0.737444918174949, 0.7264121114538001, 0.7133695725698419, 0.7476323136755818, 0.726854508853197, 0.7111584953876777, 0.7008930873050235, 0.7209375615129192, 0.7303553716733908, 0.7274869207330491, 0.7025657075988269, 0.7298115760258881, 0.7294980584878026, 0.7215147068185102, 0.7130781095091867, 0.7393833032570581, 0.7258310816144985, 0.7358941798147411, 0.736029494090402, 0.7085098152301276, 0.7472962776291713, 0.7329024831531535, 0.7124169515124726, 0.71223975981198, 0.7365416322783028, 0.7133690799930356, 0.7078738356977186, 0.7032248108904495, 0.7196096371031628, 0.7244863338885654, 0.7321533684342264, 0.7376946446827494, 0.7132714209987683, 0.7023481768180954, 0.7051334608870933, 0.7280006345208285, 0.7150799992177622, 0.7321333453970806, 0.7173964318670598]\n" + ] + } + ], + "source": [ + "list10temp=data.values.tolist()\n", + "list10 = [j for i in list10temp for j in i if j >= 0.7 if j<= 0.75]\n", + "print (list10)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/main.ipynb b/your-code/main.ipynb index c5931c4..53681ae 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -29,10 +29,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "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": [ + "lista=[i for i in range(1,51)]\n", + "print (lista)" + ] }, { "cell_type": "markdown", @@ -43,10 +54,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "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, 200]\n" + ] + } + ], + "source": [ + "lst_even=[i for i in range (2,201,2)]\n", + "print (lst_even)" + ] }, { "cell_type": "markdown", @@ -57,7 +79,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -75,10 +97,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "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": [ + "lista3=[j for i in a for j in i]\n", + "print (lista3)" + ] }, { "cell_type": "markdown", @@ -89,10 +122,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "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": [ + "lista4=[j for i in a for j in i if j >= 0.5]\n", + "print (lista4)" + ] }, { "cell_type": "markdown", @@ -103,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -125,10 +169,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "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": [ + "lista5=[k for i in b for j in i for k in j]\n", + "\n", + "print (lista5)" + ] }, { "cell_type": "markdown", @@ -139,10 +195,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "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": [ + "lista5a = [k for i in b for j in i for k in j if k == j[-1] if k <= 0.5]\n", + "\n", + "print (lista5a)" + ] }, { "cell_type": "markdown", @@ -153,10 +221,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['sample_file_0.csv', 'sample_file_1.csv', 'sample_file_2.csv', 'sample_file_3.csv', 'sample_file_4.csv', 'sample_file_5.csv', 'sample_file_6.csv', 'sample_file_7.csv', 'sample_file_8.csv', 'sample_file_9.csv']\n" + ] + } + ], + "source": [ + "file_list = [f for f in os.listdir('../data') if f.endswith('.csv')]\n", + "\n", + "print(file_list)" + ] }, { "cell_type": "markdown", @@ -167,10 +247,58 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "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_sets = [pd.read_csv(os.path.join('../data', f)) for f in file_list]\n", + "data = pd.concat(data_sets, axis=0)\n", + "top10 = data[0:10]\n", + "\n", + "print(top10)" + ] }, { "cell_type": "markdown", @@ -181,10 +309,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['0', '1', '3', '4', '5', '6', '7', '8', '10', '11', '13', '15', '16', '18', '19']\n" + ] + } + ], + "source": [ + "selected_columns = [col for col in data._get_numeric_data() if data[col].median() > .48]\n", + "print(selected_columns)" + ] }, { "cell_type": "markdown", @@ -195,10 +334,58 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "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 ... 11 12 13 14 \\\n", + "0 0.058092 0.753502 0.587513 ... 0.178356 0.182922 0.147631 0.391188 \n", + "1 0.601524 0.688753 0.338870 ... 0.471474 0.267443 0.453351 0.800716 \n", + "2 0.584542 0.032594 0.589775 ... 0.650973 0.565705 0.691784 0.265223 \n", + "3 0.260279 0.528873 0.168043 ... 0.677014 0.175735 0.632370 0.926715 \n", + "4 0.892210 0.381701 0.415264 ... 0.696930 0.819751 0.944029 0.869965 \n", + "0 0.250324 0.147078 0.162984 ... 0.509619 0.593212 0.911839 0.257645 \n", + "1 0.087914 0.960261 0.580840 ... 0.661459 0.674085 0.049326 0.785803 \n", + "2 0.680720 0.340412 0.462513 ... 0.251949 0.032847 0.995700 0.816563 \n", + "3 0.934502 0.080322 0.763502 ... 0.027637 0.409665 0.942846 0.133256 \n", + "4 0.847157 0.771811 0.233944 ... 0.053030 0.208551 0.824354 0.588567 \n", + "\n", + " 15 16 17 18 19 20 \n", + "0 0.816049 0.749068 0.293260 0.937828 0.880858 0.780858 \n", + "1 0.045749 0.683793 0.389789 0.016787 0.503695 0.403695 \n", + "2 0.739031 0.560394 0.334802 0.517694 0.646110 0.546110 \n", + "3 0.085675 0.120525 0.141746 0.771144 0.489660 0.389660 \n", + "4 0.041723 0.819140 0.676051 0.109349 0.872947 0.772947 \n", + "0 0.386457 0.696932 0.069162 0.952291 0.286542 0.186542 \n", + "1 0.315645 0.495355 0.232135 0.549324 0.572232 0.472232 \n", + "2 0.735692 0.435998 0.430411 0.531757 0.489528 0.389528 \n", + "3 0.157158 0.929446 0.402791 0.685976 0.246594 0.146594 \n", + "4 0.604341 0.232964 0.229109 0.022881 0.479022 0.379022 \n", + "\n", + "[10 rows x 21 columns]\n" + ] + } + ], + "source": [ + "data['20']=data['19']-0.1\n", + "top10b=data[0:10]\n", + "print (top10b)" + ] }, { "cell_type": "markdown", @@ -209,15 +396,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.7347510852128797, 0.7343092314001137, 0.7490680818183477, 0.7390312927111312, 0.7159290265157912, 0.7356923324968598, 0.7357618655811269, 0.7306642125209889, 0.7033930409580709, 0.7013619954419494, 0.7396561066717461, 0.7045750112959754, 0.7383982036983279, 0.7178166705957928, 0.7088042362916818, 0.737444918174949, 0.7264121114538001, 0.7133695725698419, 0.7476323136755818, 0.726854508853197, 0.7111584953876777, 0.7008930873050235, 0.7209375615129192, 0.7303553716733908, 0.7274869207330491, 0.7025657075988269, 0.7298115760258881, 0.7294980584878026, 0.7215147068185102, 0.7130781095091867, 0.7393833032570581, 0.7258310816144985, 0.7358941798147411, 0.736029494090402, 0.7085098152301276, 0.7472962776291713, 0.7329024831531535, 0.7124169515124726, 0.71223975981198, 0.7365416322783028, 0.7133690799930356, 0.7078738356977186, 0.7032248108904495, 0.7196096371031628, 0.7244863338885654, 0.7321533684342264, 0.7376946446827494, 0.7132714209987683, 0.7023481768180954, 0.7051334608870933, 0.7280006345208285, 0.7150799992177622, 0.7321333453970806, 0.7173964318670598]\n" + ] + } + ], + "source": [ + "list10temp=data.values.tolist()\n", + "list10 = [j for i in list10temp for j in i if j >= 0.7 if j<= 0.75]\n", + "print (list10)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -231,7 +430,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.10.3" } }, "nbformat": 4,