diff --git a/Numpy (26.02)/Numpy_Task.ipynb b/Numpy (26.02)/Numpy_Task.ipynb index 593ba20..b9d2a97 100644 --- a/Numpy (26.02)/Numpy_Task.ipynb +++ b/Numpy (26.02)/Numpy_Task.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "medieval-detail" }, @@ -25,16 +25,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "entertaining-automation" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n" + ] + } + ], "source": [ "python_list = [1, 12, 13, 45, 76, 45, 98, 0]\n", - "print()\n", - "python_list = \n", - "print()" + "print(type(python_list))\n", + "if type(python_list) != type(np.array([1,2,3])):\n", + " python_list = np.array([1, 12, 13, 45, 76, 45, 98, 0])\n", + "print(type(python_list))" ] }, { @@ -49,13 +59,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "id": "included-polymer" }, - "outputs": [], - "source": [ - "z = \n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5]\n" + ] + } + ], + "source": [ + "z = np.array([1.5 for i in range(10)])\n", "print(z)" ] }, @@ -71,13 +89,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "alert-endorsement" }, - "outputs": [], - "source": [ - "z = \n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0.]]\n" + ] + } + ], + "source": [ + "z = np.zeros((5, 5))\n", "print(z)" ] }, @@ -93,13 +123,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "static-filing" }, - "outputs": [], - "source": [ - "ones = \n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1 1 1 1 1 1 1 1 1 1 1 1]\n" + ] + } + ], + "source": [ + "ones = np.ones(12, int)\n", "print(ones)" ] }, @@ -116,14 +154,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "id": "outstanding-deviation" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(3, 4)\n" + ] + } + ], "source": [ - "ones = \n", - "ones.shape" + "ones = ones.reshape(3,4)\n", + "print(ones.shape)" ] }, { @@ -139,15 +185,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "foster-memory" }, - "outputs": [], - "source": [ - "Z = \n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[ 1 2 3 4 5]\n", + " [ 6 7 8 9 10]\n", + " [11 12 13 14 15]\n", + " [16 17 18 19 20]]\n", + "[[ 1 2 3 4 5]\n", + " [ 6 7 8 9 10]\n", + " [ 11 12 13 -99 15]\n", + " [ 16 17 18 19 20]]\n" + ] + } + ], + "source": [ + "Z = np.arange(1, 21, 1).reshape(4,5)\n", "print(Z)\n", - "\n", + "Z[2,3] = -99\n", "print(Z)" ] }, @@ -164,20 +225,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "magnetic-leone" }, - "outputs": [], - "source": [ - "first = \n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 1 8 1 9 4 2 -6 1 -10 -5 -2 2 8 -9 2]\n", + "[ 2 -9 8 2 -2 -5 -10 1 -6 2 4 9 1 8 1]\n" + ] + } + ], + "source": [ + "first = np.random.randint(-10, 10, 15)\n", "print(first)\n", - "second = \n", + "second = first[::-1]\n", "print(second)" ] }, { "cell_type": "markdown", + "id": "a36a3e71", "metadata": { "id": "executed-september" }, @@ -189,15 +260,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "pharmaceutical-sigma" }, - "outputs": [], - "source": [ - "first = \n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[ -1 4 12 13 5]\n", + " [ -4 8 -13 3 8]\n", + " [ -3 -7 -8 -14 5]\n", + " [ 11 -10 2 -11 8]\n", + " [ 0 -13 13 -8 -12]]\n", + "[[ 1 4 12 13 5]\n", + " [ 16 8 169 3 8]\n", + " [ 9 49 64 196 5]\n", + " [ 11 100 2 121 8]\n", + " [ 0 169 13 64 144]]\n" + ] + } + ], + "source": [ + "first = np.random.randint(-15, 15, 25).reshape(5,5)\n", "print(first)\n", - "\n", + "first = np.where(first < 0, first ** 2, first)\n", "print(first)" ] }, @@ -216,14 +304,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "id": "saving-conference" }, - "outputs": [], - "source": [ - "first = \n", - "print(first)\n" + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[ 6 -1 2 4 9]\n", + " [ 6 -15 -11 2 -1]\n", + " [ 3 6 -1 -4 11]]\n", + "11\n", + "-15\n", + "[ 5. -3.33333333 -3.33333333 0.66666667 6.33333333]\n", + "[[ 4. ]\n", + " [-3.8]\n", + " [ 3. ]]\n" + ] + } + ], + "source": [ + "first = np.random.randint(-15, 15, 15).reshape(3,5)\n", + "print(first)\n", + "print(first.max())\n", + "print(first.min())\n", + "print(np.mean(first, axis=0))\n", + "print(np.mean(first, axis=1, keepdims = True))" ] }, { @@ -234,24 +342,38 @@ "source": [ "10. Задание\n", "- даны две матрицы\n", - "- убедитесь, что их можно пермножить\n", + "- убедитесь, что их можно перемножить\n", "- произведите операцию умножения матриц, если это возможно, иначе выведите ошибку" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "id": "olympic-qatar" }, - "outputs": [], - "source": [ + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ошибка:\n", + " NoneType: None\n", + "\n" + ] + } + ], + "source": [ + "import traceback as TB\n", "a = np.random.randint(-10, 10, (2, 5))\n", "first_axis = np.random.randint(4, 6)\n", "b = np.random.randint(-10, 10, (first_axis, 3))\n", - "if :\n", + "a_cols, a_rows = a.shape\n", + "b_cols, b_rows = b.shape\n", + "if a_cols == b_rows:\n", " print(a @ b)\n", "else:\n", + " print(\"Ошибка:\\n\", TB.format_exc())\n", " " ] }, @@ -262,20 +384,33 @@ }, "source": [ "11. Задание\n", - "- создайте матрицу 5 на 5 заполненную равномерным распределением с диапазоно 2-12\n", + "- создайте матрицу 5 на 5 заполненную равномерным распределением с диапазоном 2-12\n", "- заполните все элементы ниже главной диагонали нулями" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "id": "suffering-mauritius" }, - "outputs": [], - "source": [ - "mask = \n", - "matrix = \n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[ 2. 2.41666667 2.83333333 3.25 3.66666667]\n", + " [ 0. 4.5 4.91666667 5.33333333 5.75 ]\n", + " [ 0. 0. 7. 7.41666667 7.83333333]\n", + " [ 0. 0. 0. 9.5 9.91666667]\n", + " [ 0. 0. 0. 0. 12. ]]\n" + ] + } + ], + "source": [ + "mask = np.linspace(2, 12, 25).reshape(5,5)\n", + "matrix = mask.copy()\n", + "matrix[np.tril_indices(matrix.shape[0], -1)] = 0\n", "\n", "print(matrix)" ] @@ -293,14 +428,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "id": "refined-stuff" }, - "outputs": [], - "source": [ - "mask = \n", - "matrix = \n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[ 0. 11.36173105 6.7402793 8.17221732 12.27853604]\n", + " [ 8.472255 0. 8.11683358 11.9007047 12.44620796]\n", + " [11.57158374 11.94478374 0. 8.50439505 12.83912319]\n", + " [11.94046684 12.16194725 8.75240452 0. 9.13760981]\n", + " [13.42320754 7.31427126 11.08302544 7.78806653 0. ]]\n" + ] + } + ], + "source": [ + "mask = np.random.normal(10, 2, (5,5))\n", + "matrix = mask.copy()\n", + "matrix[np.diag_indices(matrix.shape[0])] = 0\n", "\n", "print(matrix)" ] @@ -317,18 +465,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "id": "french-fighter" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0 1 0 0 0]\n", + "[0 1 1 0 1]\n" + ] + }, + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a = np.random.randint(0,2,5)\n", "print(a)\n", "b = np.random.randint(0,2,5)\n", "print(b)\n", - "equal = \n", - "equal" + "equal = np.array_equal(a, b)\n", + "print(equal)" ] }, { @@ -347,18 +514,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": { "id": "close-daisy" }, - "outputs": [], - "source": [ - "r, c = \n", - "a = \n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[ 0 1 2 3 4]\n", + " [ 5 6 7 8 9]\n", + " [10 11 12 13 14]\n", + " [15 16 17 18 19]\n", + " [20 21 22 23 24]]\n", + "3\n", + "[4 4 3]\n" + ] + } + ], + "source": [ + "import random\n", + "r, c = np.random.randint(3, 7), np.random.randint(2, 12)\n", + "a = np.arange(c*r).reshape(c, r)\n", "print(a)\n", - "N = \n", + "N = np.random.randint(1, c*r/2)\n", "print(N)\n", - "sample = \n", + "sample = np.random.choice(len(a), N)\n", "print(sample)" ] }, @@ -376,16 +558,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": { "id": "taken-fabric" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 1. nan inf]\n", + "True\n", + "True\n", + "[ 1. nan 0.]\n" + ] + } + ], "source": [ "a = np.array([1, np.NaN, np.Inf], float)\n", - "\n", - "\n", - "a" + "print(a)\n", + "b = np.isnan(np.sum(a))\n", + "print(b)\n", + "p_inf = float('inf')\n", + "print(True if p_inf in a else False)\n", + "for el in range(len(a)):\n", + " if a[el] == p_inf:\n", + " a[el] = 0\n", + "print(a)" ] }, { @@ -427,17 +626,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": { "id": "concerned-anthropology" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[52.20775932 30.19150217 50.261176 ]\n", + " [65.59280208 37.85034956 50.09220901]\n", + " [54.97263164 58.35747892 70.62018064]\n", + " [57.68496382 54.97566162 48.22621436]\n", + " [48.5413732 47.08179466 56.64566913]\n", + " [50.26419415 56.38997267 65.77505173]\n", + " [45.49849946 59.67596385 68.09244623]\n", + " [51.35971923 54.35640519 59.00483874]\n", + " [46.02726669 38.05911086 43.98274226]\n", + " [46.80264796 48.24939083 38.81326668]]\n", + "[0, 0, 2, 0, 2, 2, 2, 2, 0, 1]\n", + "[52.20775932318098, 65.59280207594934, 70.62018064397768, 57.68496382153903, 56.64566912840646, 65.77505173483584, 68.09244622514544, 59.004838735349026, 46.02726669185543, 48.24939082685686]\n" + ] + } + ], "source": [ "matrix = np.random.normal(50, 10, (10,3))\n", "print(matrix)\n", - "indexes = \n", + "\n", + "indexes = []\n", + "for i in range(10):\n", + " indexes.append(np.argmax(matrix[i]))\n", "print(indexes)\n", - "print(...)" + "\n", + "elements = []\n", + "for i in range(len(indexes)):\n", + " elements.append(matrix[i][indexes[i]])\n", + "print(elements)" ] } ], @@ -462,7 +687,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.9.7" } }, "nbformat": 4, diff --git a/Pandas (06.03)/Pandas. Task. Part 1.ipynb b/Pandas (06.03)/Pandas. Task. Part 1.ipynb index 5172e85..7cc30a0 100644 --- a/Pandas (06.03)/Pandas. Task. Part 1.ipynb +++ b/Pandas (06.03)/Pandas. Task. Part 1.ipynb @@ -1 +1 @@ -{"nbformat":4,"nbformat_minor":0,"metadata":{"anaconda-cloud":{},"kernelspec":{"display_name":"Python 3","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.7.6"},"colab":{"name":"01_task_pandas.ipynb","provenance":[],"collapsed_sections":[]}},"cells":[{"cell_type":"markdown","metadata":{"id":"UTKVH3sMutTM"},"source":["**В задании предлагается с помощью Pandas ответить на несколько вопросов по данным репозитория UCI [Adult](https://archive.ics.uci.edu/ml/datasets/Adult)**"]},{"cell_type":"markdown","metadata":{"id":"3lUT-CqYutTO"},"source":["Уникальные значения признаков (больше информации по ссылке выше):\n","- age: continuous.\n","- workclass: Private, Self-emp-not-inc, Self-emp-inc, Federal-gov, Local-gov, State-gov, Without-pay, Never-worked.\n","- fnlwgt: continuous.\n","- education: Bachelors, Some-college, 11th, HS-grad, Prof-school, Assoc-acdm, Assoc-voc, 9th, 7th-8th, 12th, Masters, 1st-4th, 10th, Doctorate, 5th-6th, Preschool.\n","- education-num: continuous.\n","- marital-status: Married-civ-spouse, Divorced, Never-married, Separated, Widowed, Married-spouse-absent, Married-AF-spouse.\n","- occupation: Tech-support, Craft-repair, Other-service, Sales, Exec-managerial, Prof-specialty, Handlers-cleaners, Machine-op-inspct, Adm-clerical, Farming-fishing, Transport-moving, Priv-house-serv, Protective-serv, Armed-Forces.\n","- relationship: Wife, Own-child, Husband, Not-in-family, Other-relative, Unmarried.\n","- race: White, Asian-Pac-Islander, Amer-Indian-Eskimo, Other, Black.\n","- sex: Female, Male.\n","- capital-gain: continuous.\n","- capital-loss: continuous.\n","- hours-per-week: continuous.\n","- native-country: United-States, Cambodia, England, Puerto-Rico, Canada, Germany, Outlying-US(Guam-USVI-etc), India, Japan, Greece, South, China, Cuba, Iran, Honduras, Philippines, Italy, Poland, Jamaica, Vietnam, Mexico, Portugal, Ireland, France, Dominican-Republic, Laos, Ecuador, Taiwan, Haiti, Columbia, Hungary, Guatemala, Nicaragua, Scotland, Thailand, Yugoslavia, El-Salvador, Trinadad&Tobago, Peru, Hong, Holand-Netherlands. \n","- salary: >50K,<=50K"]},{"cell_type":"code","metadata":{"id":"6GzulHvOutTR"},"source":["import pandas as pd"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"SJ3LbaoiutTT","colab":{"base_uri":"https://localhost:8080/","height":380},"executionInfo":{"status":"ok","timestamp":1626441443051,"user_tz":-300,"elapsed":499,"user":{"displayName":"Александр Аксёнов","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhmPE3kg2vafh4QNEoLX_DeI08tDxoR8I8MoJZP=s64","userId":"11145992452404092449"}},"outputId":"eab110b9-0f5f-4bcd-db91-328a0b391379"},"source":["data = pd.read_csv(\"https://raw.githubusercontent.com/aksenov7/Kaggle_competition_group/master/adult.data.csv\")\n","data.head()"],"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
ageworkclassfnlwgteducationeducation-nummarital-statusoccupationrelationshipracesexcapital-gaincapital-losshours-per-weeknative-countrysalary
039State-gov77516Bachelors13Never-marriedAdm-clericalNot-in-familyWhiteMale2174040United-States<=50K
150Self-emp-not-inc83311Bachelors13Married-civ-spouseExec-managerialHusbandWhiteMale0013United-States<=50K
238Private215646HS-grad9DivorcedHandlers-cleanersNot-in-familyWhiteMale0040United-States<=50K
353Private23472111th7Married-civ-spouseHandlers-cleanersHusbandBlackMale0040United-States<=50K
428Private338409Bachelors13Married-civ-spouseProf-specialtyWifeBlackFemale0040Cuba<=50K
\n","
"],"text/plain":[" age workclass fnlwgt ... hours-per-week native-country salary\n","0 39 State-gov 77516 ... 40 United-States <=50K\n","1 50 Self-emp-not-inc 83311 ... 13 United-States <=50K\n","2 38 Private 215646 ... 40 United-States <=50K\n","3 53 Private 234721 ... 40 United-States <=50K\n","4 28 Private 338409 ... 40 Cuba <=50K\n","\n","[5 rows x 15 columns]"]},"metadata":{"tags":[]},"execution_count":3}]},{"cell_type":"code","metadata":{"id":"EpQFv8t1ds05"},"source":["# def married(row):\n","# return \"Married\" in row\n","data[\"married\"] = data[\"marital-status\"].apply(lambda row: \"Married\" in row)"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":756},"id":"3Bb2mRTEeoJK","executionInfo":{"status":"ok","timestamp":1626441731759,"user_tz":-300,"elapsed":481,"user":{"displayName":"Александр Аксёнов","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhmPE3kg2vafh4QNEoLX_DeI08tDxoR8I8MoJZP=s64","userId":"11145992452404092449"}},"outputId":"9dd7d83b-f51a-4e11-f6dc-035a844f81c9"},"source":["data"],"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
ageworkclassfnlwgteducationeducation-nummarital-statusoccupationrelationshipracesexcapital-gaincapital-losshours-per-weeknative-countrysalarymarried
039State-gov77516Bachelors13Never-marriedAdm-clericalNot-in-familyWhiteMale2174040United-States<=50KFalse
150Self-emp-not-inc83311Bachelors13Married-civ-spouseExec-managerialHusbandWhiteMale0013United-States<=50KTrue
238Private215646HS-grad9DivorcedHandlers-cleanersNot-in-familyWhiteMale0040United-States<=50KFalse
353Private23472111th7Married-civ-spouseHandlers-cleanersHusbandBlackMale0040United-States<=50KTrue
428Private338409Bachelors13Married-civ-spouseProf-specialtyWifeBlackFemale0040Cuba<=50KTrue
...................................................
3255627Private257302Assoc-acdm12Married-civ-spouseTech-supportWifeWhiteFemale0038United-States<=50KTrue
3255740Private154374HS-grad9Married-civ-spouseMachine-op-inspctHusbandWhiteMale0040United-States>50KTrue
3255858Private151910HS-grad9WidowedAdm-clericalUnmarriedWhiteFemale0040United-States<=50KFalse
3255922Private201490HS-grad9Never-marriedAdm-clericalOwn-childWhiteMale0020United-States<=50KFalse
3256052Self-emp-inc287927HS-grad9Married-civ-spouseExec-managerialWifeWhiteFemale15024040United-States>50KTrue
\n","

32561 rows × 16 columns

\n","
"],"text/plain":[" age workclass fnlwgt ... native-country salary married\n","0 39 State-gov 77516 ... United-States <=50K False\n","1 50 Self-emp-not-inc 83311 ... United-States <=50K True\n","2 38 Private 215646 ... United-States <=50K False\n","3 53 Private 234721 ... United-States <=50K True\n","4 28 Private 338409 ... Cuba <=50K True\n","... ... ... ... ... ... ... ...\n","32556 27 Private 257302 ... United-States <=50K True\n","32557 40 Private 154374 ... United-States >50K True\n","32558 58 Private 151910 ... United-States <=50K False\n","32559 22 Private 201490 ... United-States <=50K False\n","32560 52 Self-emp-inc 287927 ... United-States >50K True\n","\n","[32561 rows x 16 columns]"]},"metadata":{"tags":[]},"execution_count":10}]},{"cell_type":"markdown","metadata":{"id":"MoK8B5fIutTW"},"source":["**1. Сколько мужчин и женщин (признак *sex*) представлено в этом наборе данных?**"]},{"cell_type":"code","metadata":{"collapsed":true,"id":"hdzky90TutTY"},"source":["# Ваш код здесь"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"adF8lgVbutTZ"},"source":["**2. Каков средний возраст (признак *age*) женщин?**"]},{"cell_type":"code","metadata":{"collapsed":true,"id":"K6C2qZ_zutTb"},"source":["# Ваш код здесь"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"-Cz1S7-HutTd"},"source":["**3. Какова доля граждан Германии (признак *native-country*)?**"]},{"cell_type":"code","metadata":{"collapsed":true,"id":"Y4mmqN6outTf"},"source":["# Ваш код здесь"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Do-rEgaautTg"},"source":["**4-5. Каковы средние значения и среднеквадратичные отклонения возраста тех, кто получает более 50K в год (признак *salary*) и тех, кто получает менее 50K в год? **"]},{"cell_type":"code","metadata":{"collapsed":true,"id":"eSuk0CAnutTh"},"source":["# Ваш код здесь"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"rK9SwvI_utTj"},"source":["**6. Правда ли, что люди, которые получают больше 50k, имеют как минимум высшее образование? (признак *education – Bachelors, Prof-school, Assoc-acdm, Assoc-voc, Masters* или *Doctorate*)**"]},{"cell_type":"code","metadata":{"collapsed":true,"id":"eygYabkdutTj"},"source":["# Ваш код здесь"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"4DqPASEsutTk"},"source":["**7. Выведите статистику возраста для каждой расы (признак *race*) и каждого пола. Используйте *groupby* и *describe*. Найдите таким образом максимальный возраст мужчин расы *Amer-Indian-Eskimo*.**"]},{"cell_type":"code","metadata":{"collapsed":true,"id":"fYkBDZMdutTl"},"source":["# Ваш код здесь"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"cn-jYXhzutTl"},"source":["**8. Среди кого больше доля зарабатывающих много (>50K): среди женатых или холостых мужчин (признак *marital-status*)? Женатыми считаем тех, у кого *marital-status* начинается с *Married* (Married-civ-spouse, Married-spouse-absent или Married-AF-spouse), остальных считаем холостыми.**"]},{"cell_type":"code","metadata":{"collapsed":true,"id":"4hIQXgGAutTm"},"source":["# Ваш код здесь"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Rsh8YvoXutTm"},"source":["**9. Какое максимальное число часов человек работает в неделю (признак *hours-per-week*)? Сколько людей работают такое количество часов и каков среди них процент зарабатывающих много?**"]},{"cell_type":"code","metadata":{"collapsed":true,"id":"RK1JQSIZutTn"},"source":["# Ваш код здесь"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"kUXV84AjutTn"},"source":["**10. Посчитайте среднее время работы (*hours-per-week*) зарабатывающих мало и много (*salary*) для каждой страны (*native-country*).**"]},{"cell_type":"code","metadata":{"collapsed":true,"id":"3gzYG3CDutTn"},"source":["# Ваш код здесь"],"execution_count":null,"outputs":[]}]} \ No newline at end of file +{"cells":[{"cell_type":"markdown","metadata":{"id":"UTKVH3sMutTM"},"source":["**В задании предлагается с помощью Pandas ответить на несколько вопросов по данным репозитория UCI [Adult](https://archive.ics.uci.edu/ml/datasets/Adult)**"]},{"cell_type":"markdown","metadata":{"id":"3lUT-CqYutTO"},"source":["Уникальные значения признаков (больше информации по ссылке выше):\n","- age: continuous.\n","- workclass: Private, Self-emp-not-inc, Self-emp-inc, Federal-gov, Local-gov, State-gov, Without-pay, Never-worked.\n","- fnlwgt: continuous.\n","- education: Bachelors, Some-college, 11th, HS-grad, Prof-school, Assoc-acdm, Assoc-voc, 9th, 7th-8th, 12th, Masters, 1st-4th, 10th, Doctorate, 5th-6th, Preschool.\n","- education-num: continuous.\n","- marital-status: Married-civ-spouse, Divorced, Never-married, Separated, Widowed, Married-spouse-absent, Married-AF-spouse.\n","- occupation: Tech-support, Craft-repair, Other-service, Sales, Exec-managerial, Prof-specialty, Handlers-cleaners, Machine-op-inspct, Adm-clerical, Farming-fishing, Transport-moving, Priv-house-serv, Protective-serv, Armed-Forces.\n","- relationship: Wife, Own-child, Husband, Not-in-family, Other-relative, Unmarried.\n","- race: White, Asian-Pac-Islander, Amer-Indian-Eskimo, Other, Black.\n","- sex: Female, Male.\n","- capital-gain: continuous.\n","- capital-loss: continuous.\n","- hours-per-week: continuous.\n","- native-country: United-States, Cambodia, England, Puerto-Rico, Canada, Germany, Outlying-US(Guam-USVI-etc), India, Japan, Greece, South, China, Cuba, Iran, Honduras, Philippines, Italy, Poland, Jamaica, Vietnam, Mexico, Portugal, Ireland, France, Dominican-Republic, Laos, Ecuador, Taiwan, Haiti, Columbia, Hungary, Guatemala, Nicaragua, Scotland, Thailand, Yugoslavia, El-Salvador, Trinadad&Tobago, Peru, Hong, Holand-Netherlands. \n","- salary: >50K,<=50K"]},{"cell_type":"code","execution_count":1,"metadata":{"id":"6GzulHvOutTR"},"outputs":[],"source":["import pandas as pd"]},{"cell_type":"code","execution_count":3,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":380},"executionInfo":{"elapsed":499,"status":"ok","timestamp":1626441443051,"user":{"displayName":"Александр Аксёнов","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhmPE3kg2vafh4QNEoLX_DeI08tDxoR8I8MoJZP=s64","userId":"11145992452404092449"},"user_tz":-300},"id":"SJ3LbaoiutTT","outputId":"eab110b9-0f5f-4bcd-db91-328a0b391379"},"outputs":[{"data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
ageworkclassfnlwgteducationeducation-nummarital-statusoccupationrelationshipracesexcapital-gaincapital-losshours-per-weeknative-countrysalary
039State-gov77516Bachelors13Never-marriedAdm-clericalNot-in-familyWhiteMale2174040United-States<=50K
150Self-emp-not-inc83311Bachelors13Married-civ-spouseExec-managerialHusbandWhiteMale0013United-States<=50K
238Private215646HS-grad9DivorcedHandlers-cleanersNot-in-familyWhiteMale0040United-States<=50K
353Private23472111th7Married-civ-spouseHandlers-cleanersHusbandBlackMale0040United-States<=50K
428Private338409Bachelors13Married-civ-spouseProf-specialtyWifeBlackFemale0040Cuba<=50K
\n","
"],"text/plain":[" age workclass fnlwgt education education-num \\\n","0 39 State-gov 77516 Bachelors 13 \n","1 50 Self-emp-not-inc 83311 Bachelors 13 \n","2 38 Private 215646 HS-grad 9 \n","3 53 Private 234721 11th 7 \n","4 28 Private 338409 Bachelors 13 \n","\n"," marital-status occupation relationship race sex \\\n","0 Never-married Adm-clerical Not-in-family White Male \n","1 Married-civ-spouse Exec-managerial Husband White Male \n","2 Divorced Handlers-cleaners Not-in-family White Male \n","3 Married-civ-spouse Handlers-cleaners Husband Black Male \n","4 Married-civ-spouse Prof-specialty Wife Black Female \n","\n"," capital-gain capital-loss hours-per-week native-country salary \n","0 2174 0 40 United-States <=50K \n","1 0 0 13 United-States <=50K \n","2 0 0 40 United-States <=50K \n","3 0 0 40 United-States <=50K \n","4 0 0 40 Cuba <=50K "]},"execution_count":3,"metadata":{},"output_type":"execute_result"}],"source":["data = pd.read_csv(\"https://raw.githubusercontent.com/aksenov7/Kaggle_competition_group/master/adult.data.csv\")\n","data.head()"]},{"cell_type":"code","execution_count":4,"metadata":{"id":"EpQFv8t1ds05"},"outputs":[],"source":["# def married(row):\n","# return \"Married\" in row\n","data[\"married\"] = data[\"marital-status\"].apply(lambda row: \"Married\" in row)"]},{"cell_type":"code","execution_count":5,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":756},"executionInfo":{"elapsed":481,"status":"ok","timestamp":1626441731759,"user":{"displayName":"Александр Аксёнов","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhmPE3kg2vafh4QNEoLX_DeI08tDxoR8I8MoJZP=s64","userId":"11145992452404092449"},"user_tz":-300},"id":"3Bb2mRTEeoJK","outputId":"9dd7d83b-f51a-4e11-f6dc-035a844f81c9"},"outputs":[{"data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
ageworkclassfnlwgteducationeducation-nummarital-statusoccupationrelationshipracesexcapital-gaincapital-losshours-per-weeknative-countrysalarymarried
039State-gov77516Bachelors13Never-marriedAdm-clericalNot-in-familyWhiteMale2174040United-States<=50KFalse
150Self-emp-not-inc83311Bachelors13Married-civ-spouseExec-managerialHusbandWhiteMale0013United-States<=50KTrue
238Private215646HS-grad9DivorcedHandlers-cleanersNot-in-familyWhiteMale0040United-States<=50KFalse
353Private23472111th7Married-civ-spouseHandlers-cleanersHusbandBlackMale0040United-States<=50KTrue
428Private338409Bachelors13Married-civ-spouseProf-specialtyWifeBlackFemale0040Cuba<=50KTrue
...................................................
3255627Private257302Assoc-acdm12Married-civ-spouseTech-supportWifeWhiteFemale0038United-States<=50KTrue
3255740Private154374HS-grad9Married-civ-spouseMachine-op-inspctHusbandWhiteMale0040United-States>50KTrue
3255858Private151910HS-grad9WidowedAdm-clericalUnmarriedWhiteFemale0040United-States<=50KFalse
3255922Private201490HS-grad9Never-marriedAdm-clericalOwn-childWhiteMale0020United-States<=50KFalse
3256052Self-emp-inc287927HS-grad9Married-civ-spouseExec-managerialWifeWhiteFemale15024040United-States>50KTrue
\n","

32561 rows × 16 columns

\n","
"],"text/plain":[" age workclass fnlwgt education education-num \\\n","0 39 State-gov 77516 Bachelors 13 \n","1 50 Self-emp-not-inc 83311 Bachelors 13 \n","2 38 Private 215646 HS-grad 9 \n","3 53 Private 234721 11th 7 \n","4 28 Private 338409 Bachelors 13 \n","... ... ... ... ... ... \n","32556 27 Private 257302 Assoc-acdm 12 \n","32557 40 Private 154374 HS-grad 9 \n","32558 58 Private 151910 HS-grad 9 \n","32559 22 Private 201490 HS-grad 9 \n","32560 52 Self-emp-inc 287927 HS-grad 9 \n","\n"," marital-status occupation relationship race sex \\\n","0 Never-married Adm-clerical Not-in-family White Male \n","1 Married-civ-spouse Exec-managerial Husband White Male \n","2 Divorced Handlers-cleaners Not-in-family White Male \n","3 Married-civ-spouse Handlers-cleaners Husband Black Male \n","4 Married-civ-spouse Prof-specialty Wife Black Female \n","... ... ... ... ... ... \n","32556 Married-civ-spouse Tech-support Wife White Female \n","32557 Married-civ-spouse Machine-op-inspct Husband White Male \n","32558 Widowed Adm-clerical Unmarried White Female \n","32559 Never-married Adm-clerical Own-child White Male \n","32560 Married-civ-spouse Exec-managerial Wife White Female \n","\n"," capital-gain capital-loss hours-per-week native-country salary \\\n","0 2174 0 40 United-States <=50K \n","1 0 0 13 United-States <=50K \n","2 0 0 40 United-States <=50K \n","3 0 0 40 United-States <=50K \n","4 0 0 40 Cuba <=50K \n","... ... ... ... ... ... \n","32556 0 0 38 United-States <=50K \n","32557 0 0 40 United-States >50K \n","32558 0 0 40 United-States <=50K \n","32559 0 0 20 United-States <=50K \n","32560 15024 0 40 United-States >50K \n","\n"," married \n","0 False \n","1 True \n","2 False \n","3 True \n","4 True \n","... ... \n","32556 True \n","32557 True \n","32558 False \n","32559 False \n","32560 True \n","\n","[32561 rows x 16 columns]"]},"execution_count":5,"metadata":{},"output_type":"execute_result"}],"source":["data"]},{"cell_type":"markdown","metadata":{"id":"MoK8B5fIutTW"},"source":["**1. Сколько мужчин и женщин (признак *sex*) представлено в этом наборе данных?**"]},{"cell_type":"code","execution_count":6,"metadata":{},"outputs":[{"data":{"text/plain":["Male 21790\n","Female 10771\n","Name: sex, dtype: int64"]},"execution_count":6,"metadata":{},"output_type":"execute_result"}],"source":["data['sex'].value_counts()"]},{"cell_type":"markdown","metadata":{"id":"adF8lgVbutTZ"},"source":["**2. Каков средний возраст (признак *age*) женщин?**"]},{"cell_type":"code","execution_count":16,"metadata":{"collapsed":true,"id":"K6C2qZ_zutTb"},"outputs":[{"data":{"text/plain":["36.85823043357163"]},"execution_count":16,"metadata":{},"output_type":"execute_result"}],"source":["data[data[\"sex\"] == \"Female\"][\"age\"].mean()"]},{"cell_type":"markdown","metadata":{"id":"-Cz1S7-HutTd"},"source":["**3. Какова доля граждан Германии (признак *native-country*)?**"]},{"cell_type":"code","execution_count":21,"metadata":{"collapsed":true,"id":"Y4mmqN6outTf"},"outputs":[{"data":{"text/plain":["0.42074874850281013"]},"execution_count":21,"metadata":{},"output_type":"execute_result"}],"source":["len(data[data[\"native-country\"] == \"Germany\"]) / len(data) * 100"]},{"cell_type":"markdown","metadata":{"id":"Do-rEgaautTg"},"source":["**4-5. Каковы средние значения и среднеквадратичные отклонения возраста тех, кто получает более 50K в год (признак *salary*) и тех, кто получает менее 50K в год? **"]},{"cell_type":"code","execution_count":23,"metadata":{"collapsed":true,"id":"eSuk0CAnutTh"},"outputs":[{"name":"stdout","output_type":"stream","text":["Средние значения:\n","больше 50К: 44.24984058155847\n","меньше или 50К: 36.78373786407767\n","Среднеквадратичные значения:\n","больше 50К: 44.24984058155847\n","меньше или 50К: 36.78373786407767\n"]}],"source":["dataframe_1 = data.groupby(\"salary\")[\"age\"].mean()\n","print(\"Средние значения:\")\n","print(\"больше 50К: \", dataframe_1[\">50K\"])\n","print(\"меньше или 50К: \", dataframe_1[\"<=50K\"])\n","\n","dataframe_2 = data.groupby(\"salary\")[\"age\"].std()\n","print(\"Среднеквадратичные значения:\")\n","print(\"больше 50К: \", dataframe_1[\">50K\"])\n","print(\"меньше или 50К: \", dataframe_1[\"<=50K\"])"]},{"cell_type":"markdown","metadata":{"id":"rK9SwvI_utTj"},"source":["**6. Правда ли, что люди, которые получают больше 50k, имеют как минимум высшее образование? (признак *education – Bachelors, Prof-school, Assoc-acdm, Assoc-voc, Masters* или *Doctorate*)**"]},{"cell_type":"code","execution_count":29,"metadata":{"collapsed":true,"id":"eygYabkdutTj"},"outputs":[{"name":"stdout","output_type":"stream","text":["True\n"]}],"source":["dataframe = data[data[\"salary\"]==\">50K\"]\n","print(\"True\") if (\"Bachelors\" or \"Prof-school\" or \"Assoc-acdm\" or \"Assoc-voc\" or \"Master\" or \"Doctorate\" in dataframe) else print(\"False\")"]},{"cell_type":"markdown","metadata":{"id":"4DqPASEsutTk"},"source":["**7. Выведите статистику возраста для каждой расы (признак *race*) и каждого пола. Используйте *groupby* и *describe*. Найдите таким образом максимальный возраст мужчин расы *Amer-Indian-Eskimo*.**"]},{"cell_type":"code","execution_count":35,"metadata":{"collapsed":true,"id":"fYkBDZMdutTl"},"outputs":[{"name":"stdout","output_type":"stream","text":["Максимальный возраст мужчин расы Amer-Indian-Eskimo: 82.0\n"]}],"source":["dataframe = data.groupby([\"race\", \"sex\"]).describe().loc['Amer-Indian-Eskimo'].loc[\"Male\"]\n","print(\"Максимальный возраст мужчин расы Amer-Indian-Eskimo: \", dataframe[\"age\"][\"max\"])"]},{"cell_type":"markdown","metadata":{"id":"cn-jYXhzutTl"},"source":["**8. Среди кого больше доля зарабатывающих много (>50K): среди женатых или холостых мужчин (признак *marital-status*)? Женатыми считаем тех, у кого *marital-status* начинается с *Married* (Married-civ-spouse, Married-spouse-absent или Married-AF-spouse), остальных считаем холостыми.**"]},{"cell_type":"code","execution_count":45,"metadata":{"collapsed":true,"id":"4hIQXgGAutTm"},"outputs":[{"name":"stdout","output_type":"stream","text":["Доля больше среди женатых: True\n"]}],"source":["dataframe = data[data[\"salary\"]==\">50K\"]\n","dataframe = dataframe[dataframe[\"sex\"] == \"Male\"]\n","married_men = len(dataframe[dataframe[\"marital-status\"]==\"Married-civ-spouse\"]) + len(dataframe[dataframe[\"marital-status\"]==\"Married-spouse-absent\"]) + len(dataframe[dataframe[\"marital-status\"]==\"Married-AF-spouse\"])\n","print(\"Доля больше среди женатых: \", married_men > len(dataframe) - married_men)"]},{"cell_type":"markdown","metadata":{"id":"Rsh8YvoXutTm"},"source":["**9. Какое максимальное число часов человек работает в неделю (признак *hours-per-week*)? Сколько людей работают такое количество часов и каков среди них процент зарабатывающих много?**"]},{"cell_type":"code","execution_count":58,"metadata":{"collapsed":true,"id":"RK1JQSIZutTn"},"outputs":[{"name":"stdout","output_type":"stream","text":["Максимум часов в неделю: 99 .\n","85 людей работает макстмальное число часов в неделю.\n","Процент тех, кто работает максимум часов: 29.41176470588235 .\n"]}],"source":["max_hours_per_week = data[\"hours-per-week\"].max()\n","print(\"Максимум часов в неделю:\", max_hours_per_week, \".\")\n","working_men = data[data[\"hours-per-week\"] == max_hours_per_week]\n","print(len(working_men), \"людей работает макстмальное число часов в неделю.\")\n","procent = len(working_men[working_men[\"salary\"] == \">50K\"])\n","print(\"Процент тех, кто работает максимум часов:\", procent * 100 / len(working_men), \".\")"]},{"cell_type":"markdown","metadata":{"id":"kUXV84AjutTn"},"source":["**10. Посчитайте среднее время работы (*hours-per-week*) зарабатывающих мало и много (*salary*) для каждой страны (*native-country*).**"]},{"cell_type":"code","execution_count":59,"metadata":{"collapsed":true,"id":"3gzYG3CDutTn"},"outputs":[{"name":"stdout","output_type":"stream","text":["Среднее время работы для каждой страны:\n"," native-country salary\n","? <=50K 40.164760\n"," >50K 45.547945\n","Cambodia <=50K 41.416667\n"," >50K 40.000000\n","Canada <=50K 37.914634\n"," ... \n","United-States >50K 45.505369\n","Vietnam <=50K 37.193548\n"," >50K 39.200000\n","Yugoslavia <=50K 41.600000\n"," >50K 49.500000\n","Name: hours-per-week, Length: 82, dtype: float64\n"]}],"source":["print(\"Среднее время работы для каждой страны:\\n\", data.groupby(['native-country', 'salary'])['hours-per-week'].mean())"]}],"metadata":{"anaconda-cloud":{},"colab":{"collapsed_sections":[],"name":"01_task_pandas.ipynb","provenance":[]},"kernelspec":{"display_name":"Python 3","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.9.7"}},"nbformat":4,"nbformat_minor":0} diff --git a/Pandas and EDA (12.03)/Pandas and EDA. Task.ipynb b/Pandas and EDA (12.03)/Pandas and EDA. Task.ipynb index bb60a1c..739aee3 100644 --- a/Pandas and EDA (12.03)/Pandas and EDA. Task.ipynb +++ b/Pandas and EDA (12.03)/Pandas and EDA. Task.ipynb @@ -1 +1 @@ -{"nbformat":4,"nbformat_minor":0,"metadata":{"kernelspec":{"display_name":"Python 3","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.6.8"},"colab":{"name":"02_pandas_task.ipynb","provenance":[],"collapsed_sections":[]}},"cells":[{"cell_type":"markdown","metadata":{"id":"EmV0s8YY05p7"},"source":["- __ID__ - Unique number for each athlete\n","- __Name__ - Athlete's name\n","- __Sex__ - M or F\n","- __Age__ - Integer\n","- __Height__ - In centimeters\n","- __Weight__ - In kilograms\n","- __Team__ - Team name\n","- __NOC__ - National Olympic Committee 3-letter code\n","- __Games__ - Year and season\n","- __Year__ - Integer\n","- __Season__ - Summer or Winter\n","- __City__ - Host city\n","- __Sport__ - Sport\n","- __Event__ - Event\n","- __Medal__ - Gold, Silver, Bronze, or NA"]},{"cell_type":"code","metadata":{"id":"rVCrMDMh05p_"},"source":["import pandas as pd"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"D5Q4Z-JW05qC"},"source":["# не меняем путь!\n","PATH = 'https://github.com/aksenov7/Kaggle_competition_group/blob/master/athlete_events.csv.zip?raw=true'"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"mI0LtqkY4Kp-"},"source":["__0. Откройте файл используя необходимые параметры и не меняя переменную PATH__"]},{"cell_type":"code","metadata":{"id":"h5SQwBLr05qG","colab":{"base_uri":"https://localhost:8080/","height":206},"executionInfo":{"status":"ok","timestamp":1615627554682,"user_tz":-300,"elapsed":2477,"user":{"displayName":"Александр Аксёнов","photoUrl":"https://lh5.googleusercontent.com/-jOf_oDVHsg8/AAAAAAAAAAI/AAAAAAAAAFM/qwdbG0GW_To/s64/photo.jpg","userId":"11145992452404092449"}},"outputId":"882f9e83-5fd7-4c3b-b005-56917b15a0fd"},"source":["data = \n","data.head()"],"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
IDNameSexAgeHeightWeightTeamNOCGamesYearSeasonCitySportEventMedal
01A DijiangM24.0180.080.0ChinaCHN1992 Summer1992SummerBarcelonaBasketballBasketball Men's BasketballNaN
12A LamusiM23.0170.060.0ChinaCHN2012 Summer2012SummerLondonJudoJudo Men's Extra-LightweightNaN
23Gunnar Nielsen AabyM24.0NaNNaNDenmarkDEN1920 Summer1920SummerAntwerpenFootballFootball Men's FootballNaN
34Edgar Lindenau AabyeM34.0NaNNaNDenmark/SwedenDEN1900 Summer1900SummerParisTug-Of-WarTug-Of-War Men's Tug-Of-WarGold
45Christine Jacoba AaftinkF21.0185.082.0NetherlandsNED1988 Winter1988WinterCalgarySpeed SkatingSpeed Skating Women's 500 metresNaN
\n","
"],"text/plain":[" ID Name ... Event Medal\n","0 1 A Dijiang ... Basketball Men's Basketball NaN\n","1 2 A Lamusi ... Judo Men's Extra-Lightweight NaN\n","2 3 Gunnar Nielsen Aaby ... Football Men's Football NaN\n","3 4 Edgar Lindenau Aabye ... Tug-Of-War Men's Tug-Of-War Gold\n","4 5 Christine Jacoba Aaftink ... Speed Skating Women's 500 metres NaN\n","\n","[5 rows x 15 columns]"]},"metadata":{"tags":[]},"execution_count":3}]},{"cell_type":"markdown","metadata":{"id":"stYR4EbV05qP"},"source":["__1. Сколько лет было самым молодым мужчинам и женщинам-участникам Олимпийских игр 1992 года ?__\n","- 16 и 15\n","- 14 и 13 \n","- 13 и 11\n","- 11 и 12"]},{"cell_type":"code","metadata":{"id":"HgiqBXtb05qR"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"GQ290dsi05qc"},"source":["__2. Каков был процент баскетболистов-мужчин среди всех мужчин-участников Олимпийских игр 2012 года? Округлите ответ до первого десятичного знака.__\n","\n","Здесь и далее при необходимости отбрасывайте дублированных спортсменов, чтобы считать только уникальных . \n","- 0.2\n","- 1.5 \n","- 2.5\n","- 7.7"]},{"cell_type":"code","metadata":{"id":"-fI5MqWP05qi"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"u5WrTgIC05qv"},"source":["__3. Каковы среднее и стандартное отклонение роста теннисисток, участвовавших в Олимпийских играх 2000 года? Округлите ответ до первого десятичного знака.__\n","\n","- 171.8 и 6.5\n","- 179.4 и 10\n","- 180.7 и 6.7\n","- 182.4 и 9.1 "]},{"cell_type":"code","metadata":{"id":"vsKTqn6405qw"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"xOOEzhNQ05qy"},"source":["__4. Найдите спортсмена, который участвовал в Олимпийских играх 2006 года, с наибольшим весом среди других участников той же Олимпиады. Каким спортом он или она занимался?__\n","\n","- Judo\n","- Bobsleigh \n","- Skeleton\n","- Boxing"]},{"cell_type":"code","metadata":{"id":"EkWD1Tnb05qz"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"UQzxZ3HT05q0"},"source":["__5. Сколько раз John Aalberg участвовал в Олимпийских играх в разные годы?__\n","\n","Один год - это один раз. Неважно сколько участий внутри одного года\n","- 0\n","- 1 \n","- 2\n","- 3 "]},{"cell_type":"code","metadata":{"id":"ZSfkdjPO05q0"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"8EnLcNrk05q3"},"source":["__6. Сколько золотых медалей по теннису выиграли спортсмены сборной Switzerland на Олимпиаде-2008? Считайте каждую медаль от каждого спортсмена.__\n","\n","- 0\n","- 1 \n","- 2\n","- 3 "]},{"cell_type":"code","metadata":{"id":"Y754OGI-05q3"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"v3h5sQF805q5"},"source":["__7. Правда ли, что на Олимпийских играх 2016 Spain выиграла меньше медалей, чем Италия?__ \n","\n","- Да\n","- Нет"]},{"cell_type":"code","metadata":{"id":"gqJqDi2605q7"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"kkSYL5mK05q-"},"source":["__8. К какой возрастной категории принадлежало наименьшее и наибольшее количество участников Олимпиады-2008?__\n","\n","- [45-55] и [25-35) соответственно\n","- [45-55] и [15-25) соответственно\n","- [35-45) и [25-35) соответственно\n","- [45-55] и [35-45) соответственно"]},{"cell_type":"code","metadata":{"id":"pMAQtW7i05q_"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"JQmJPiXv05rB"},"source":["__9. Правда ли, что в Atlanta проводились летние Олимпийские игры? Правда ли, что в Squaw Valley проводились зимние Олимпийские игры? ?__\n","\n","- Да, Да\n","- Да, Нет\n","- Нет, Да \n","- Нет, Нет "]},{"cell_type":"code","metadata":{"id":"UU66wRHC05rB"},"source":[""],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"4hxR5D-t05rF"},"source":["__10. Какова абсолютная разница между количеством уникальных видов спорта на Олимпиаде 1986 года и Олимпиаде 2002 года?__\n","\n","- 3 \n","- 10\n","- 15\n","- 27 "]},{"cell_type":"code","metadata":{"id":"WKIr-TR105rF"},"source":[""],"execution_count":null,"outputs":[]}]} \ No newline at end of file +{"cells":[{"cell_type":"markdown","metadata":{"id":"EmV0s8YY05p7"},"source":["- __ID__ - Unique number for each athlete\n","- __Name__ - Athlete's name\n","- __Sex__ - M or F\n","- __Age__ - Integer\n","- __Height__ - In centimeters\n","- __Weight__ - In kilograms\n","- __Team__ - Team name\n","- __NOC__ - National Olympic Committee 3-letter code\n","- __Games__ - Year and season\n","- __Year__ - Integer\n","- __Season__ - Summer or Winter\n","- __City__ - Host city\n","- __Sport__ - Sport\n","- __Event__ - Event\n","- __Medal__ - Gold, Silver, Bronze, or NA"]},{"cell_type":"code","execution_count":2,"metadata":{"id":"rVCrMDMh05p_"},"outputs":[],"source":["import pandas as pd"]},{"cell_type":"code","execution_count":3,"metadata":{"id":"D5Q4Z-JW05qC"},"outputs":[],"source":["# не меняем путь!\n","PATH = 'https://github.com/aksenov7/Kaggle_competition_group/blob/master/athlete_events.csv.zip?raw=true'"]},{"cell_type":"markdown","metadata":{"id":"mI0LtqkY4Kp-"},"source":["__0. Откройте файл используя необходимые параметры и не меняя переменную PATH__"]},{"cell_type":"code","execution_count":4,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":206},"executionInfo":{"elapsed":2477,"status":"ok","timestamp":1615627554682,"user":{"displayName":"Александр Аксёнов","photoUrl":"https://lh5.googleusercontent.com/-jOf_oDVHsg8/AAAAAAAAAAI/AAAAAAAAAFM/qwdbG0GW_To/s64/photo.jpg","userId":"11145992452404092449"},"user_tz":-300},"id":"h5SQwBLr05qG","outputId":"882f9e83-5fd7-4c3b-b005-56917b15a0fd"},"outputs":[{"data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
IDNameSexAgeHeightWeightTeamNOCGamesYearSeasonCitySportEventMedal
01A DijiangM24.0180.080.0ChinaCHN1992 Summer1992SummerBarcelonaBasketballBasketball Men's BasketballNaN
12A LamusiM23.0170.060.0ChinaCHN2012 Summer2012SummerLondonJudoJudo Men's Extra-LightweightNaN
23Gunnar Nielsen AabyM24.0NaNNaNDenmarkDEN1920 Summer1920SummerAntwerpenFootballFootball Men's FootballNaN
34Edgar Lindenau AabyeM34.0NaNNaNDenmark/SwedenDEN1900 Summer1900SummerParisTug-Of-WarTug-Of-War Men's Tug-Of-WarGold
45Christine Jacoba AaftinkF21.0185.082.0NetherlandsNED1988 Winter1988WinterCalgarySpeed SkatingSpeed Skating Women's 500 metresNaN
\n","
"],"text/plain":[" ID Name Sex Age Height Weight Team \\\n","0 1 A Dijiang M 24.0 180.0 80.0 China \n","1 2 A Lamusi M 23.0 170.0 60.0 China \n","2 3 Gunnar Nielsen Aaby M 24.0 NaN NaN Denmark \n","3 4 Edgar Lindenau Aabye M 34.0 NaN NaN Denmark/Sweden \n","4 5 Christine Jacoba Aaftink F 21.0 185.0 82.0 Netherlands \n","\n"," NOC Games Year Season City Sport \\\n","0 CHN 1992 Summer 1992 Summer Barcelona Basketball \n","1 CHN 2012 Summer 2012 Summer London Judo \n","2 DEN 1920 Summer 1920 Summer Antwerpen Football \n","3 DEN 1900 Summer 1900 Summer Paris Tug-Of-War \n","4 NED 1988 Winter 1988 Winter Calgary Speed Skating \n","\n"," Event Medal \n","0 Basketball Men's Basketball NaN \n","1 Judo Men's Extra-Lightweight NaN \n","2 Football Men's Football NaN \n","3 Tug-Of-War Men's Tug-Of-War Gold \n","4 Speed Skating Women's 500 metres NaN "]},"execution_count":4,"metadata":{},"output_type":"execute_result"}],"source":["data = pd.read_csv(PATH, compression='zip', sep=',')\n","data.head()"]},{"cell_type":"markdown","metadata":{"id":"stYR4EbV05qP"},"source":["__1. Сколько лет было самым молодым мужчинам и женщинам-участникам Олимпийских игр 1992 года ?__\n","- 16 и 15\n","- 14 и 13 \n","- 13 и 11\n","- 11 и 12"]},{"cell_type":"code","execution_count":5,"metadata":{"id":"HgiqBXtb05qR"},"outputs":[{"name":"stdout","output_type":"stream","text":["Самым молодым мужчинам было: 11\n","Самым молодым женщинам было: 12\n"]}],"source":["df_0 = data[data[\"Year\"] == 1992]\n","df_1 = df_0[df_0[\"Sex\"] == 'M'][\"Age\"].min()\n","print(\"Самым молодым мужчинам было: \", int(df_1))\n","df_2 = df_0[df_0[\"Sex\"] == 'F'][\"Age\"].min()\n","print(\"Самым молодым женщинам было: \", int(df_2))"]},{"cell_type":"markdown","metadata":{"id":"GQ290dsi05qc"},"source":["__2. Каков был процент баскетболистов-мужчин среди всех мужчин-участников Олимпийских игр 2012 года? Округлите ответ до первого десятичного знака.__\n","\n","Здесь и далее при необходимости отбрасывайте дублированных спортсменов, чтобы считать только уникальных . \n","- 0.2\n","- 1.5 \n","- 2.5\n","- 7.7"]},{"cell_type":"code","execution_count":6,"metadata":{"id":"-fI5MqWP05qi"},"outputs":[{"name":"stdout","output_type":"stream","text":["Процент баскетболистов-мужчин среди всех мужчин-участников: 2.5\n"]}],"source":["df = data[data[\"Year\"] == 2012]\n","df_1 = df[df[\"Sex\"] == \"M\"]\n","df_2 = df_1[df_1[\"Sport\"] == \"Basketball\"]\n","procent = len(df_2[\"ID\"].drop_duplicates()) / len(df_1[\"ID\"].drop_duplicates()) * 100\n","print(\"Процент баскетболистов-мужчин среди всех мужчин-участников: \", str(round(procent, 1)))"]},{"cell_type":"markdown","metadata":{"id":"u5WrTgIC05qv"},"source":["__3. Каковы среднее и стандартное отклонение роста теннисисток, участвовавших в Олимпийских играх 2000 года? Округлите ответ до первого десятичного знака.__\n","\n","- 171.8 и 6.5\n","- 179.4 и 10\n","- 180.7 и 6.7\n","- 182.4 и 9.1 "]},{"cell_type":"code","execution_count":7,"metadata":{"id":"vsKTqn6405qw"},"outputs":[{"name":"stdout","output_type":"stream","text":["Среднее отклонение роста теннистисток: 171.8\n","Стандартное отклонение роста теннистисток: 6.5\n"]}],"source":["df = data[data[\"Year\"] == 2000]\n","df_1 = df[df[\"Sex\"] == \"F\"]\n","df_2 = df_1[df_1[\"Sport\"] == \"Tennis\"]\n","print(\"Среднее отклонение роста теннистисток: \", round(df_2[\"Height\"].mean(), 1))\n","print(\"Стандартное отклонение роста теннистисток: \", round(df_2[\"Height\"].std(), 1))"]},{"cell_type":"markdown","metadata":{"id":"xOOEzhNQ05qy"},"source":["__4. Найдите спортсмена, который участвовал в Олимпийских играх 2006 года, с наибольшим весом среди других участников той же Олимпиады. Каким спортом он или она занимался?__\n","\n","- Judo\n","- Bobsleigh \n","- Skeleton\n","- Boxing"]},{"cell_type":"code","execution_count":27,"metadata":{"id":"EkWD1Tnb05qz"},"outputs":[{"name":"stdout","output_type":"stream","text":["Спорт: 8102 Skeleton\n","Name: Sport, dtype: object\n"]}],"source":["df = data[data[\"Year\"] == 2006]\n","max_weight = df[\"Weight\"].max()\n","sportsman = df[df[\"Weight\"] == max_weight]\n","print('Спорт: ', sportsman[\"Sport\"])"]},{"cell_type":"markdown","metadata":{"id":"UQzxZ3HT05q0"},"source":["__5. Сколько раз John Aalberg участвовал в Олимпийских играх в разные годы?__\n","\n","Один год - это один раз. Неважно сколько участий внутри одного года\n","- 0\n","- 1 \n","- 2\n","- 3 "]},{"cell_type":"code","execution_count":17,"metadata":{"id":"ZSfkdjPO05q0"},"outputs":[{"name":"stdout","output_type":"stream","text":["John Aalberg участвовал 2 раз(-а) в Олипийских играх в разные годы!\n"]}],"source":["df_0 = data[data[\"Name\"] == \"John Aalberg\"]\n","participations = len(df_0[\"Age\"].drop_duplicates())\n","print(\"John Aalberg участвовал\", participations, \"раз(-а) в Олипийских играх в разные годы!\")"]},{"cell_type":"markdown","metadata":{"id":"8EnLcNrk05q3"},"source":["__6. Сколько золотых медалей по теннису выиграли спортсмены сборной Switzerland на Олимпиаде-2008? Считайте каждую медаль от каждого спортсмена.__\n","\n","- 0\n","- 1 \n","- 2\n","- 3 "]},{"cell_type":"code","execution_count":25,"metadata":{"id":"Y754OGI-05q3"},"outputs":[{"name":"stdout","output_type":"stream","text":["2 золотые медали выиграли теннисисты из Швейцарии\n"]}],"source":["df_0 = data[data[\"Team\"] == \"Switzerland\"]\n","df_1 = df_0[df_0[\"Sport\"] == \"Tennis\"]\n","df_2 = df_1[df_1[\"Year\"] == 2008]\n","df_3 = df_2[df_2[\"Medal\"] == \"Gold\"]\n","print(len(df_3), \"золотые медали выиграли теннисисты из Швейцарии.\")"]},{"cell_type":"markdown","metadata":{"id":"v3h5sQF805q5"},"source":["__7. Правда ли, что на Олимпийских играх 2016 Spain выиграла меньше медалей, чем Италия?__ \n","\n","- Да\n","- Нет"]},{"cell_type":"code","execution_count":91,"metadata":{"id":"gqJqDi2605q7"},"outputs":[{"name":"stdout","output_type":"stream","text":["Да\n"]}],"source":["df_0 = data[data[\"Year\"] == 2016]\n","Spain_all = df_0[df_0[\"Team\"] == \"Spain\"][\"Medal\"].dropna()\n","Italy_all = df_0[df_0[\"Team\"] == \"Italy\"][\"Medal\"].dropna()\n","print(\"Да\") if len(Spain_all) < len(Italy_all) else print(\"Нет\")"]},{"cell_type":"markdown","metadata":{"id":"kkSYL5mK05q-"},"source":["__8. К какой возрастной категории принадлежало наименьшее и наибольшее количество участников Олимпиады-2008?__\n","\n","- [45-55] и [25-35) соответственно\n","- [45-55] и [15-25) соответственно\n","- [35-45) и [25-35) соответственно\n","- [45-55] и [35-45) соответственно"]},{"cell_type":"code","execution_count":26,"metadata":{"id":"pMAQtW7i05q_"},"outputs":[{"name":"stdout","output_type":"stream","text":["[45-55] [25-35) "]}],"source":["df = data[data[\"Year\"] == 2008]\n","df_groups = [\n"," len(df[(df[\"Age\"] >= 45) & (df[\"Age\"] <= 55)]),\n"," len(df[(df[\"Age\"] >= 25) & (df[\"Age\"] < 35)]),\n"," len(df[(df[\"Age\"] >= 15) & (df[\"Age\"] < 25)]),\n"," len(df[(df[\"Age\"] >= 35) & (df[\"Age\"] < 45)])\n","]\n","_max_ = max(df_groups)\n","_min_ = min(df_groups)\n","dictionary = {\n"," 0 : \"[45-55]\",\n"," 1 : \"[25-35)\",\n"," 2 : \"[15-25)\",\n"," 3 : \"[35-45]\"\n","}\n","#дальше я хотел красиво вывести результат\n","#flag = False\n","for i in range(len(df_groups)):\n"," if df_groups[i] == _max_: print(dictionary.get(i), end=' ')\n"," if df_groups[i] == _min_: print(dictionary.get(i), end=' ')\n"]},{"cell_type":"markdown","metadata":{"id":"JQmJPiXv05rB"},"source":["__9. Правда ли, что в Atlanta проводились летние Олимпийские игры? Правда ли, что в Squaw Valley проводились зимние Олимпийские игры? ?__\n","\n","- Да, Да\n","- Да, Нет\n","- Нет, Да \n","- Нет, Нет "]},{"cell_type":"code","execution_count":66,"metadata":{"id":"UU66wRHC05rB"},"outputs":[{"name":"stdout","output_type":"stream","text":["Да, Да\n"]}],"source":["df_Atlanta = data[(data[\"City\"] == \"Atlanta\") & (data[\"Season\"] == \"Summer\")]\n","df_Squaw_Valley = data[(data[\"City\"] == \"Squaw Valley\") & (data[\"Season\"] == \"Winter\")]\n","print(\"Да, \", end='') if len(df_Atlanta) > 0 else print(\"Нет, \", end='')\n","print(\"Да\") if len(df_Squaw_Valley) > 0 else print(\"Нет\")"]},{"cell_type":"markdown","metadata":{"id":"4hxR5D-t05rF"},"source":["__10. Какова абсолютная разница между количеством уникальных видов спорта на Олимпиаде 1986 года и Олимпиаде 2002 года?__\n","\n","- 3 \n","- 10\n","- 15\n","- 27 "]},{"cell_type":"code","execution_count":80,"metadata":{"id":"WKIr-TR105rF"},"outputs":[{"name":"stdout","output_type":"stream","text":["Абсолютная разница уникальных видов спорта: 15\n"]}],"source":["df_1986 = data[data[\"Year\"] == 1986].drop_duplicates(\"Sport\")\n","df_2002 = data[data[\"Year\"] == 2002].drop_duplicates(\"Sport\")\n","print(\"Абсолютная разница уникальных видов спорта:\", str(abs(len(df_1986) - len(df_2002))))"]}],"metadata":{"colab":{"collapsed_sections":[],"name":"02_pandas_task.ipynb","provenance":[]},"kernelspec":{"display_name":"Python 3","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.9.7"}},"nbformat":4,"nbformat_minor":0}