You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3060 lines
192 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "a83d3451",
"metadata": {},
"source": [
"# Лабораторная работа №3"
]
},
{
"cell_type": "markdown",
"id": "c4626d84",
"metadata": {},
"source": [
"Данная лабораторная предназначена для ознакомления с основными модулями Python используемыми в анализе данных.\n",
"\n",
"NumPy - модуль предназначенный для работы с многомерными массивами. Почитать можно [здесь](https://pythonworld.ru/numpy)\n",
"\n",
"Matplotlib - пакет модулей предназначенный для визуализации данных. Почитать можно [здесь](https://pythonworld.ru/novosti-mira-python/scientific-graphics-in-python.html) \n",
"\n",
"Pandas - модуль для анализа данных и поддерживающий их табличное представление. Почитать можно [здесь](https://pythonworld.ru/obrabotka-dannyx/pandas-cookbook-1-csv-reading.html)\n",
"\n",
"Для углубленного изучения можно почитать книгу Дж. Вандел Плас Python для сложных задач наука о данных:\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "044a3a41",
"metadata": {},
"source": [
"## NumPy\n",
"\n",
"Данный модуль создан для ускорения работы с массивами больших размерностей. Для примера рассмотрим сравнение скорости подсчета суммы случайного ряда при помощи встроенных инструментов и инструментов numpy:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "fb97f953",
"metadata": {},
"outputs": [],
"source": [
"# импортируем модуль и создадим ему короткий псевдоним для удобства обращения к нему\n",
"import numpy as np\n",
"\n",
"# импортируем этот модуль для генерации случайных данных\n",
"import random"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "4d629828",
"metadata": {},
"outputs": [],
"source": [
"# создадим список длиной 10_000 случайных целых чисел в диапазоне от -10_000 до 10_000\n",
"arr = random.sample(range(-10_000, 10_000),k=10_000)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0701ca1a",
"metadata": {},
"outputs": [],
"source": [
"# Подсчитаем время исполнения ячейки при помощи волшебного оператора %%time"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "062a85f3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"101 µs ± 556 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
]
}
],
"source": [
"%timeit sum(arr)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "86298baf",
"metadata": {},
"outputs": [],
"source": [
"# Подсчитаем теперь преобразованный список в NumPy-массив при помощи np.sum()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "ee277123",
"metadata": {},
"outputs": [],
"source": [
"arr_2 = np.array(arr)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "e58e9290",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5.18 µs ± 17.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
]
}
],
"source": [
"%timeit np.sum(arr_2)"
]
},
{
"cell_type": "markdown",
"id": "48501958",
"metadata": {},
"source": [
"Как видно алгоритм подсчет суммы ускоряется почти в 20 раз"
]
},
{
"cell_type": "markdown",
"id": "06dd75f1",
"metadata": {},
"source": [
"NumPy позволяет создавать различного рода матрицы в одно действие: "
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "9930b6c6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0., 0.],\n",
" [0., 0.]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#создать матрицу размерности 2х2 заполненную нулями\n",
"np.zeros((2,2))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "55ed68ec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1., 1.],\n",
" [1., 1.],\n",
" [1., 1.]])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#создать матрицу размерности 3х2 заполненную единицами\n",
"np.ones((3,2))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "5e86bd15",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[1 2]\n",
" [3 4]\n",
" [5 6]]\n",
"(3, 2)\n"
]
}
],
"source": [
"# размерность массива можно посмотреть вызвав поле shape у np.array\n",
"\n",
"a = np.array([[1, 2], [3, 4], [5, 6]])\n",
"\n",
"print(a)\n",
"print(a.shape)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "166f7114",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n"
]
}
],
"source": [
"# len вернет нам вернет размер по первому измерению\n",
"\n",
"print(len(a))"
]
},
{
"cell_type": "markdown",
"id": "885f11a7",
"metadata": {},
"source": [
"### Задание\n",
"\n",
"Найдите в документации numpy функции для создания диагональной матрицы и заполнения матрицы пользовательским числом.\n",
"\n",
"1) Создайте диагональную единичную матрицу размерности 5х5\n",
"\n",
"2) Создайте матрицу размерности 4х4 заполненную тройками"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b85793e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "d8cd415d",
"metadata": {},
"source": [
"Массивы можно транспонировать и изменять размерности"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "8c9ea473",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[1 2]\n",
" [3 4]\n",
" [5 6]]\n"
]
}
],
"source": [
"a = np.array([[1,2],[3,4],[5,6]])\n",
"print(a)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "058cd289",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[1 2 3]\n",
" [4 5 6]]\n"
]
}
],
"source": [
"print(a.reshape((2,3)))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "0c2bd57d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[1 3 5]\n",
" [2 4 6]]\n"
]
}
],
"source": [
"print(a.T)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "8a51aa3b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1 2 3 4 5 6]\n"
]
}
],
"source": [
"# можно так же расплющить массив в одномерный\n",
"print(a.flatten())"
]
},
{
"cell_type": "markdown",
"id": "5f356c97",
"metadata": {},
"source": [
"### Задание\n",
"Создайте матрицу (любым известным вам способом) размерности 2х3х4 и транспонируйте ее. Попробуйте поменять очередность осей (по сути если представить трехмерную матрицу как куб, то это будет поворотом в пространстве на какой-то из боков) при помощи transpose"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66d95b4c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "3e43e5ea",
"metadata": {},
"source": [
"Массивы можно объединять и добавлять новые оси"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "fff1f7a1",
"metadata": {},
"outputs": [],
"source": [
"a = np.array([[1,2],[3,4]])\n",
"b = np.array([[5,6]])"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "7ae37c0a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[1 2]\n",
" [3 4]\n",
" [5 6]]\n"
]
}
],
"source": [
"print(np.concatenate((a,b)))"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "4aafd0ee",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"old matrix\n",
"[[1 2]\n",
" [3 4]]\n",
"(2, 2) \n",
"\n",
"new matrix\n",
"[[[1]\n",
" [2]]\n",
"\n",
" [[3]\n",
" [4]]]\n",
"(2, 2, 1)\n"
]
}
],
"source": [
"print('old matrix')\n",
"print(a)\n",
"print(a.shape, '\\n') # отступим строку \n",
"\n",
"print('new matrix')\n",
"b = a[:,:,np.newaxis]\n",
"print(b)\n",
"print(b.shape)"
]
},
{
"cell_type": "markdown",
"id": "70b9a5c9",
"metadata": {},
"source": [
"### Задание\n",
"Создайте матрицу размерности 3х4 и продублируйте ее так, чтобы ее размерность стала 2х3х4 (понадобится newaxis и concatenate или при помощи squeeze)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "90c9b02e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "4a2fc50b",
"metadata": {},
"source": [
"### Операции над матрицами"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "b799f6fb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[1. 2.]\n",
" [3. 4.]] \n",
"\n",
"[[1. 0.]\n",
" [0. 1.]]\n"
]
}
],
"source": [
"# можно передавать тип данных, к которому требуется привести элементы матрицы, в данном случае float\n",
"a = np.array([[1,2],[3,4]], float)\n",
"# создадим единичную матрицу (на главной диагонали лежат единицы, все остальные элементы равны нулю)\n",
"b = np.eye(2,2)\n",
"\n",
"print(a, '\\n')\n",
"print(b)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "9b91dd3b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[2., 2.],\n",
" [3., 5.]])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a + b"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "c173c930",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0., 2.],\n",
" [3., 3.]])"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a - b"
]
},
{
"cell_type": "markdown",
"id": "aab1e5d7",
"metadata": {},
"source": [
"умножение матриц через операнд * работает как поэлементное умножение"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "a4b2adeb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1., 0.],\n",
" [0., 4.]])"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a * b"
]
},
{
"cell_type": "markdown",
"id": "9a1aaf78",
"metadata": {},
"source": [
"матрицу можно домножать на скаляр"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "d080e165",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[10., 20.],\n",
" [30., 40.]])"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a * 10"
]
},
{
"cell_type": "markdown",
"id": "642171cc",
"metadata": {},
"source": [
"и проводить все базовые математические операции со скалярами поэлементно"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "caf040de",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0., 0.],\n",
" [1., 1.]])"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a // 3"
]
},
{
"cell_type": "markdown",
"id": "7ca21353",
"metadata": {},
"source": [
"Для матричного перемножения используется метод dot()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "97af84bd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1., 2.],\n",
" [3., 4.]])"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# т.к. при умножение на единичную матрицу исходная матрица не меняется\n",
"a.dot(b)"
]
},
{
"cell_type": "markdown",
"id": "faf8a0f2",
"metadata": {},
"source": [
"### Задание\n",
"\n",
"Создайте две матрицы размерности 2х3 и 3х2, перемножьте их"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c2ad3bc9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "71bc90d2",
"metadata": {},
"source": [
"К массивам применимы те же операции, что и для списков. Их можно вызывать либо у массива, как метод, либо как функцию из numpy"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "ef0317fc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n",
"4\n"
]
}
],
"source": [
"a = np.array([[1,2],[3,4]])\n",
"\n",
"print(a.max())\n",
"print(np.max(a))"
]
},
{
"cell_type": "markdown",
"id": "448de690",
"metadata": {},
"source": [
"### Задание\n",
"\n",
"Используя возможности numpy (БЕЗ SET) напишите функции, которые принимают заданный массив чисел и возвращают:\n",
"\n",
"1) список уникальных значений\n",
"\n",
"2) кортеж из среднего, максимального и минимального"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "dff1fd72",
"metadata": {},
"outputs": [],
"source": [
"arr = np.array([1,2,3,4,5,6,7,8,8,8,9,2,3,4,17])\n",
"\n",
"def unique_values(arr):\n",
" \"\"\"\n",
" напишите здесь свое решение\n",
" \"\"\"\n",
" pass\n",
"\n",
"def mean_max_min(arr):\n",
" \"\"\"\n",
" напишите здесь свое решение\n",
" \"\"\"\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "01a9aee8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"None\n",
"None\n"
]
}
],
"source": [
"# тут менять ничего не нужно, просто исполнить ячейку\n",
"print(unique_values(arr))\n",
"print(mean_max_min(arr))"
]
},
{
"cell_type": "markdown",
"id": "faf2eea4",
"metadata": {},
"source": [
"## Matplotlib"
]
},
{
"cell_type": "markdown",
"id": "bc5e0963",
"metadata": {},
"source": [
"Данная библиотека используется для визуального представления данных (графики, гистограммы, изображения и т.д.)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "2bd5b586",
"metadata": {},
"outputs": [],
"source": [
"# импортируем модуль pyplot из пакета matplotlib и дадим общепринятое сокращенное имя plt\n",
"from matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"id": "225c8dee",
"metadata": {},
"source": [
"Рассмотрим для примера отрисовку графика синусоиды"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "1bf1604a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x169302e1cd0>]"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlsAAADCCAYAAAB+MwfTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9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vrWJwbIb/OqUOMISKK/1jvHJxgEdvKSfJuvyynvvXZLOpMI1vvdlq+AMMytlSAPCzxi5Gpz08vgJVK8hjByuZnvXxY7Wwh4TpWS9P1tu5d3M+5dlLyz+Zz7p8/8L+xFvtUSHF64GfnLTj8Ul+Z3/liq/xmQOVDI3P8MvTxt+x64Gh8Rl+3tTNB+tKrtfTWi57q7LYWpzOE2+1q/IcIeJ7R9pIiDPx6N7yFf2+EILHb62idWjC8CcTlbOlQErJj0/Y2VKUzvaSjBVfZ21eKrdUZfFkfSc+g+9C9MCL53pxTc7ysd0r26kH+eS+cobG3bxywdiTlR7weH08WW/nYHXOqvpQ7luTxbq8VJUjFCJ+eqoLt9fHo7eUr/gaQgg+truMloFx6tudoTMuRhmf8fDMmR4e3FaIbYH6c0vl3s35ZKfE85OTxj4tqpwtBac7XVzqG+PDu5YXU1+IR3aV0uWc4ui1oRBYFtv86Lidiuxk9latrh3SgeocijISebJeLeyr5dVLA/SPzvDRZeafzEcIwYd2ltDcNcLF3tEQWRebSCl5qr6TneW2FaVAzOX+bQWkxlv4SZScgNOSZ073MOn28sgq15U4s4mH64p57VI/fSPGPVmtnC0FPzlpJ8lq5sHthau+1t0b88hIiuNJg+9CtOZq/xg
"text/plain": [
"<Figure size 720x216 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# зададим функцию для подсчета значения синуса в точке\n",
"def func(x):\n",
" return np.sin(x)\n",
"\n",
"# при помощи linspace создадим массив значений в 1000 шагов от минус 5Пи до плюс 5пи \n",
"x = np.linspace(-np.pi * 5, np.pi * 5, 1000)\n",
"\n",
"# зададим параметр пропорций и размеров нашего графика (можете поменять эти значения или вообще удалить эту строчку для интереса)\n",
"plt.figure(figsize=(10,3))\n",
"# выведем график при помощи функции plot\n",
"plt.plot(x, func(x))"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "4ab380ee",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x169303e0850>]"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlsAAADCCAYAAAB+MwfTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAABOfElEQVR4nO29d3yb133v/z4ACO4B7j1FbYkiRS1LsuNtJx7NcOKMxhmNm2bcpvfmpml6u+5tfzdt03F7myZxM5zcJrHdTM/E2xrWIEWK1JYoDnAvANwkCOD8/gAg0zQlkSKA53mA8369+BIBPnier3h4zvmez/me71dIKVEoFAqFQqFQhAeT1gYoFAqFQqFQRDPK2VIoFAqFQqEII8rZUigUCoVCoQgjytlSKBQKhUKhCCPK2VIoFAqFQqEII8rZUigUCoVCoQgjFq0NuBbZ2dmyvLxcazMUCoVCoVAorsuJEydGpJQ5i9/XtbNVXl5OY2Oj1mYoFAqFQqFQXBchRNdS76ttRIVCoVAoFIowopwthUKhUCgUijASEmdLCPF9IcSQEOL0VX4uhBD/IoRoE0K0CiHqQvFchUKhUCgUCr0TKmXrceCea/z8XqA68PUo8K0QPVehUCgUCoVC14QkQF5KeUAIUX6NSx4EfiT9Va+PCiEyhBAFUsr+UDxfEV68PsnL5wY51u5AItlRnskdG/KwWtQutJZ0jkzx3Kl++sdmKMxI5L4thZRmJWltVkzj9vh44XQ/zXYXFpNgT1UWt6zNwWJWfUVLLgxM8MLpfkYm5yjPSub+mkLy0hK0NiummXZ7eP7UAKd6XCTEmdlfncPeNVkIIbQ2LSwIv/8Tghv5na1npZSbl/jZs8DXpZSHAq9fAf5YSvmOo4ZCiEfxq1+UlpZu7+paMrBfESHahib5wk+aOD8wQUKcCYFgZt5LVU4y/+fhWjYXpWttYszh9Um+8eIFHjvQjtcnsSXF4Zyex2ISfO7WNXzp9mpMpugcsPRMS7eLL/60Gb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TOelJ7wy+vhY1JRnsr87me4c6mJ03/sSuJ779xmVsSXF8ZFfpij4XPPAzOD7Hr5p7w2Rd5FDOlgKAyTkPP3yzk7s35l8zKP5qFKQn8uC2Ip5osKsVewj5/qFOPF4fv7/E6cPl8OjNlczMe/nxMTWxh4qBsVl+0dzDwztKyE1defLFtXmp3LI2hx8e6VITewj59wMdxFtMPLKn7IY+/we3VDE8McfPTqgDDKHi4uAEL58b4pGbykmyrjyt57412WwqTOM7b7Qb/gCDcrYUAPyiqYfxWQ+fvQFVK8ijN1cyO+/jJ2piDwmz816eaLBzz+Z8yrOXF3+ymHX5/on98Tc7o0KK1wM/PW7H45P83r7KG77HZ/ZXMjI5x69PGn/FrgdGJuf4ZXMvH6wvuZJPa6Xsqcpia3E6j7/ZqdJzhIjvH+ogIc7EI3vKb+jzQgg+e0sV7SNThj+ZqJwtBVJKfnLMzpaidLaVZNzwfdbmpXJTVRZPNHTjM/gqRA+8cLof1/Q8H9t1Yyv1IJ/cW87IpJuXzxp7sNIDHq+PJxrs3Fyds6o6lHvXZLEuL1XFCIWIn5/owe318chN5Td8DyEEH9tVRtvQJA2dztAZF6NMznl4uqWPB2oKsS2Rf2653LM5n+yUeH563NinRZWzpeBkt4vzAxN8eOfK9tSX4uGdpfQ4Zzh8eSQElsU2Pz5qpyI7mT1VqyuHtL86h6KMRJ5oUBP7annl/BCD43N8dIXxJ4sRQvChHSW09oxxrn88RNbFJlJKnmzoZke57YZCIBZyX00BqfEWfholJ+C05OmTfUy7vTy8ynklzmziofpiXj0/yMCYcU9WK2dLwU+P20mymnlgW+Gq73XXxjwykuJ4wuCrEK25NDh
"text/plain": [
"<Figure size 720x216 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# в аргументы передается сначала значения оси Х (можно не задавать), а потом значения по оси Y\n",
"\n",
"# обратите внимание на значения оси Х, которые мы сами не задаем\n",
"plt.figure(figsize=(10,3))\n",
"plt.plot(func(x))"
]
},
{
"cell_type": "markdown",
"id": "4e3a173a",
"metadata": {},
"source": [
"графики можно накладывать друг на друга, менять цвета и тип линии"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "dd0fa23a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x169304566a0>]"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlIAAADCCAYAAACCJiwZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAABg0klEQVR4nO2dd3gUVdvG77Ob3kmB9AJJgNAhQBJ670WlCRZQQVGUVwVEbFjRT7EgiDQRpUsNvYeQkAChE3p6IL33tuf7Y7KEkp7ZPbO753dducjszpxzk9mdeeY5TyGUUnA4HA6Hw+FwGo6MtQAOh8PhcDgcTYUbUhwOh8PhcDiNhBtSHA6Hw+FwOI2EG1IcDofD4XA4jYQbUhwOh8PhcDiNhBtSHA6Hw+FwOI1Ej8Wktra21N3dncXUHA6Hw+FwOA3i4sWL6ZRSu+reY2JIubu7IyIigsXUHA6Hw+FwOA2CEBJX03t8aY/D4XA4HA6nkXBDisPhcDgcDqeRcEOKw+FwOBwOp5FwQ4rD4XA4HA6nkTAJNudIh1tpt7Dj5g4k5yejlXUrTGo3Cc4Wzqxl6TRFZUXYHrkdEQ8jYKRnhBldZsDHzoe1LJ0n4mEEbIxt4NHMAxWKCmQWZcLOtNokHo4aicqMwq/hv8Lc0BwjvUait2tv1pJ0GkopQuJDcPDeQeSV5qGzfWdMajcJFoYWrKWpDEIpVfukvr6+lGftSYP/Iv/D5B2T0cy4GTKLMmGsZ4xvBn6D9/3eByGEtTyd41TMKby8+2U8yHsAcwNzlFaU4tSrp+Dv4s9ams6SV5KHN/e/iS03tmDp0KX4wP8DHLl/BBP/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with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,3))\n",
"\n",
"plt.plot(func(x), color='red', linestyle=':')\n",
"plt.plot(func(x)*5, color='green', linestyle='--')"
]
},
{
"cell_type": "markdown",
"id": "2e7a25d0",
"metadata": {},
"source": [
"### Задание\n",
"Постройте графики функции x^2+2x-1 и ее производной синего и оранжевого цвета соответственно"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "edf87e95",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "6183ff76",
"metadata": {},
"source": [
"При помощи imshow можно смотреть на тепловые (высотные) карты двумерных данных. Например значения функций двух переменных или изображения."
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "fd9bad72",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x169304b67c0>"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQ8AAAD8CAYAAABpXiE9AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAANmklEQVR4nO3db6ie9X3H8fdnMSr+Q12wpjFV24aBE7q6EOMcI2O1aCikD2TTB1VkcFAU2qIPpII+GmyDFeYUs0ClCkX3wFbDlq6zUqp9EKeGRI3WeXSCh4SGqYt/p0v33YNzuR2O98k553df577v2PcLbu7run6/+/p9/Rk+uf5qqgpJWq7fGncBko5NhoekJoaHpCaGh6QmhoekJoaHpCbHDfPjJGcC/wCcB7wG/GlVvTWg32vAO8CvgSNVtXGYcSWN37BHHrcCj1XVBuCxbn0hf1xVv2dwSJ8Ow4bHNuC+bvk+4OtD7k/SMSLDPGGa5D+r6vQ5629V1RkD+v078BZQwN9X1Y6j7HMKmAJYxarfP4nTm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7tlncBq5Os6WNsSePRx92WAN8DXqyq7y7Q5+yuH0k2deO+MezYksanj7stlwLfAJ5Lsrfb9h3gcwBVtR24ErghyRHgA+CqWtr50o4e6uuT9RzdpNUDk1fTp6aeXi+YSvrN4ROmkpoYHpKaTEx4JDkzyaNJXu6+z1ig32tJnusec396Beq4PMlLSaaT3DqgPUnu7NqfTXJR3zU01DSyx/+T3JvkUJKBz9+MaX4Wq2mkr0cs8ZWNkc3Tir1CUlUT8QH+Gri1W74V+KsF+r0GrFmhGlYBrwCfB44H9gEXzOuzFfgxEGAz8OQKz8tSatoC/OOI/j39EXAR8PwC7SOdnyXWNLL56cZbC1z
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"arr = np.array([[0,1,0],[1,2,1],[0,1,0]])\n",
"plt.imshow(arr)"
]
},
{
"cell_type": "markdown",
"id": "420a9abe",
"metadata": {},
"source": [
"При помощи hist можно отобразить сравнительное графическое представление данных в виде гистограммы.\n",
"\n",
"Указывая количество бинов, мы можем регулировать промежутки на которых будут формироваться столбцы"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "f2c4d922",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAQ9UlEQVR4nO3dXYxcZ33H8e+vxlYLRFDwJiC/4Fz4goDiEK1MUFDjoBI5vNRFopItCggRWUGJBBWlMlwQld5QIaEKErAssAIqSVQJAlYxJBGlDSUK9ToNSUwSujJps3KEDaHhVY1M/73YYzrZzHqOvbO7zrPfjzSac56XM8954vz27LNnZlJVSJLa9XvLPQBJ0uIy6CWpcQa9JDXOoJekxhn0ktS45y33AIZZu3Ztbdq0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HQW2LGiEkqQF8Z2xktQ4g16SGmfQS1LjDHpJapxBL0mNM+glqXEGvSQ1zqCXpMYZ9JLUOINekhpn0EtS4wx6SWqcQS9JjTPoJalxBr0kNc6gl6TGGfSS1LheQZ9ke5JHk0wn2TOkfluSp5Lc3z0+2revJGlxjfwqwSSrgJuANwIzwKEkB6rqB3Oafqeq3nKWfSVJi6TPFf1WYLqqjlbV08BtwI6ex19IX0nSGPQJ+nXA4wP7M13ZXK9L8v0k30jyqjPsS5LdSaaSTJ04caLHsCRJffQJ+gwpqzn79wGvqKotwKeBr55B39nCqn1VNVlVkxMTEz2GJUnqo0/QzwAbBvbXA8cGG1TVz6vql932QWB1krV9+kqSFlefoD8EbE5yYZI1wE7gwGCDJC9Lkm57a3fcn/bpK0laXCPvuqmqk0muB+4AVgH7q+pIkmu7+r3A24H3JTkJ/AbYWVUFDO27SOciSRpiZNDD75ZjDs4
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"data = np.array([10,4,26,17,8,45])\n",
"\n",
"plt.hist(data, bins=10)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "913b220c",
"metadata": {},
"source": [
"## Pandas"
]
},
{
"cell_type": "markdown",
"id": "af08b78f",
"metadata": {},
"source": [
"Pandas позволяет обрабатывать и анализировать данные. Можно провести аналогию с Excel.\n",
"В данном разделе рассмотрим основные возможности (т.к. библиотека крайне объемная и всю документацию будет физически невозможно сюда уместить)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "7ebddb89",
"metadata": {},
"outputs": [],
"source": [
"# Импортируем библотеку pandas и дадим ей сокращенное общепринятое имя pd \n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"id": "e4199517",
"metadata": {},
"source": [
"Pandas позволяет считывать табличные данные из файлов в форматах .csv, .xml, .xlsx, .json и т.д.\n",
"\n",
"Скачаем для примера классический датасет с информацией о пассажирах титаника.\n",
"\n",
"Линк на датасет: https://github.com/datasciencedojo/datasets/blob/master/titanic.csv"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "bbf38d57",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"Загрузим данный датасет. \n",
"т.к. он в формате .csv то воспользуемся функцией read_csv() \n",
"в которой укажем относительный путь к этому файлу \n",
"\"\"\"\n",
"df = pd.read_csv('lab_3_titanic.csv')"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "268d6ec7",
"metadata": {},
"outputs": [
{
"data": {
"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>PassengerId</th>\n",
" <th>Survived</th>\n",
" <th>Pclass</th>\n",
" <th>Name</th>\n",
" <th>Sex</th>\n",
" <th>Age</th>\n",
" <th>SibSp</th>\n",
" <th>Parch</th>\n",
" <th>Ticket</th>\n",
" <th>Fare</th>\n",
" <th>Cabin</th>\n",
" <th>Embarked</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Braund, Mr. Owen Harris</td>\n",
" <td>male</td>\n",
" <td>22.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>A/5 21171</td>\n",
" <td>7.2500</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
" <td>female</td>\n",
" <td>38.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>PC 17599</td>\n",
" <td>71.2833</td>\n",
" <td>C85</td>\n",
" <td>C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>Heikkinen, Miss. Laina</td>\n",
" <td>female</td>\n",
" <td>26.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>STON/O2. 3101282</td>\n",
" <td>7.9250</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
" <td>female</td>\n",
" <td>35.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>113803</td>\n",
" <td>53.1000</td>\n",
" <td>C123</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Allen, Mr. William Henry</td>\n",
" <td>male</td>\n",
" <td>35.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>373450</td>\n",
" <td>8.0500</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>6</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Moran, Mr. James</td>\n",
" <td>male</td>\n",
" <td>NaN</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>330877</td>\n",
" <td>8.4583</td>\n",
" <td>NaN</td>\n",
" <td>Q</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>7</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>McCarthy, Mr. Timothy J</td>\n",
" <td>male</td>\n",
" <td>54.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>17463</td>\n",
" <td>51.8625</td>\n",
" <td>E46</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>8</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Palsson, Master. Gosta Leonard</td>\n",
" <td>male</td>\n",
" <td>2.0</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>349909</td>\n",
" <td>21.0750</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>9</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)</td>\n",
" <td>female</td>\n",
" <td>27.0</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>347742</td>\n",
" <td>11.1333</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>10</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>Nasser, Mrs. Nicholas (Adele Achem)</td>\n",
" <td>female</td>\n",
" <td>14.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>237736</td>\n",
" <td>30.0708</td>\n",
" <td>NaN</td>\n",
" <td>C</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" PassengerId Survived Pclass \\\n",
"0 1 0 3 \n",
"1 2 1 1 \n",
"2 3 1 3 \n",
"3 4 1 1 \n",
"4 5 0 3 \n",
"5 6 0 3 \n",
"6 7 0 1 \n",
"7 8 0 3 \n",
"8 9 1 3 \n",
"9 10 1 2 \n",
"\n",
" Name Sex Age SibSp \\\n",
"0 Braund, Mr. Owen Harris male 22.0 1 \n",
"1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n",
"2 Heikkinen, Miss. Laina female 26.0 0 \n",
"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n",
"4 Allen, Mr. William Henry male 35.0 0 \n",
"5 Moran, Mr. James male NaN 0 \n",
"6 McCarthy, Mr. Timothy J male 54.0 0 \n",
"7 Palsson, Master. Gosta Leonard male 2.0 3 \n",
"8 Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) female 27.0 0 \n",
"9 Nasser, Mrs. Nicholas (Adele Achem) female 14.0 1 \n",
"\n",
" Parch Ticket Fare Cabin Embarked \n",
"0 0 A/5 21171 7.2500 NaN S \n",
"1 0 PC 17599 71.2833 C85 C \n",
"2 0 STON/O2. 3101282 7.9250 NaN S \n",
"3 0 113803 53.1000 C123 S \n",
"4 0 373450 8.0500 NaN S \n",
"5 0 330877 8.4583 NaN Q \n",
"6 0 17463 51.8625 E46 S \n",
"7 1 349909 21.0750 NaN S \n",
"8 2 347742 11.1333 NaN S \n",
"9 0 237736 30.0708 NaN C "
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# посмотрим первые 10 записей\n",
"df[:10]"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "044a069c",
"metadata": {},
"outputs": [
{
"data": {
"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>PassengerId</th>\n",
" <th>Survived</th>\n",
" <th>Pclass</th>\n",
" <th>Name</th>\n",
" <th>Sex</th>\n",
" <th>Age</th>\n",
" <th>SibSp</th>\n",
" <th>Parch</th>\n",
" <th>Ticket</th>\n",
" <th>Fare</th>\n",
" <th>Cabin</th>\n",
" <th>Embarked</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Braund, Mr. Owen Harris</td>\n",
" <td>male</td>\n",
" <td>22.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>A/5 21171</td>\n",
" <td>7.2500</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
" <td>female</td>\n",
" <td>38.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>PC 17599</td>\n",
" <td>71.2833</td>\n",
" <td>C85</td>\n",
" <td>C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>Heikkinen, Miss. Laina</td>\n",
" <td>female</td>\n",
" <td>26.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>STON/O2. 3101282</td>\n",
" <td>7.9250</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
" <td>female</td>\n",
" <td>35.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>113803</td>\n",
" <td>53.1000</td>\n",
" <td>C123</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Allen, Mr. William Henry</td>\n",
" <td>male</td>\n",
" <td>35.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>373450</td>\n",
" <td>8.0500</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>6</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Moran, Mr. James</td>\n",
" <td>male</td>\n",
" <td>NaN</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>330877</td>\n",
" <td>8.4583</td>\n",
" <td>NaN</td>\n",
" <td>Q</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>7</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>McCarthy, Mr. Timothy J</td>\n",
" <td>male</td>\n",
" <td>54.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>17463</td>\n",
" <td>51.8625</td>\n",
" <td>E46</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>8</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Palsson, Master. Gosta Leonard</td>\n",
" <td>male</td>\n",
" <td>2.0</td>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>349909</td>\n",
" <td>21.0750</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>9</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)</td>\n",
" <td>female</td>\n",
" <td>27.0</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>347742</td>\n",
" <td>11.1333</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>10</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>Nasser, Mrs. Nicholas (Adele Achem)</td>\n",
" <td>female</td>\n",
" <td>14.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>237736</td>\n",
" <td>30.0708</td>\n",
" <td>NaN</td>\n",
" <td>C</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" PassengerId Survived Pclass \\\n",
"0 1 0 3 \n",
"1 2 1 1 \n",
"2 3 1 3 \n",
"3 4 1 1 \n",
"4 5 0 3 \n",
"5 6 0 3 \n",
"6 7 0 1 \n",
"7 8 0 3 \n",
"8 9 1 3 \n",
"9 10 1 2 \n",
"\n",
" Name Sex Age SibSp \\\n",
"0 Braund, Mr. Owen Harris male 22.0 1 \n",
"1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n",
"2 Heikkinen, Miss. Laina female 26.0 0 \n",
"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n",
"4 Allen, Mr. William Henry male 35.0 0 \n",
"5 Moran, Mr. James male NaN 0 \n",
"6 McCarthy, Mr. Timothy J male 54.0 0 \n",
"7 Palsson, Master. Gosta Leonard male 2.0 3 \n",
"8 Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) female 27.0 0 \n",
"9 Nasser, Mrs. Nicholas (Adele Achem) female 14.0 1 \n",
"\n",
" Parch Ticket Fare Cabin Embarked \n",
"0 0 A/5 21171 7.2500 NaN S \n",
"1 0 PC 17599 71.2833 C85 C \n",
"2 0 STON/O2. 3101282 7.9250 NaN S \n",
"3 0 113803 53.1000 C123 S \n",
"4 0 373450 8.0500 NaN S \n",
"5 0 330877 8.4583 NaN Q \n",
"6 0 17463 51.8625 E46 S \n",
"7 1 349909 21.0750 NaN S \n",
"8 2 347742 11.1333 NaN S \n",
"9 0 237736 30.0708 NaN C "
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# то же самое можно сделать и так\n",
"df.head(10)"
]
},
{
"cell_type": "markdown",
"id": "09d489ac",
"metadata": {},
"source": [
"### Задание\n",
"Выведите последние 10 строк таблицы"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "beb0df55",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "ca5614f8",
"metadata": {},
"source": [
"Как видим, в таблице имеются столбцы, означающие некоторые признаки:\n",
"- PassengerId: уникальный идентификатор пассажира в данном наборе данных\n",
"- Survived: 0 - погиб, 1 - выжил\n",
"- Pclass: класс обслуживания пассажира\n",
"- Name: ФИО пассажира (как был записан в документах)\n",
"- Sex: пол пассажира\n",
"- Age: возраст пассажира\n",
"- SibSp: сколько братьев/сестер или супругов на борту\n",
"- Parch: сколько детей/родителей на борту\n",
"- Ticket: номер билета\n",
"- Fare: пассажирский тариф\n",
"- Cabin: номер каюты\n",
"- Embarked: порт погрузки. C - Cherbourg, Q - Queenstown, S - Southampton"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "14180f18",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['PassengerId',\n",
" 'Survived',\n",
" 'Pclass',\n",
" 'Name',\n",
" 'Sex',\n",
" 'Age',\n",
" 'SibSp',\n",
" 'Parch',\n",
" 'Ticket',\n",
" 'Fare',\n",
" 'Cabin',\n",
" 'Embarked']"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Получить список столбцов можно при помощи следующей функции\n",
"df.columns.to_list()"
]
},
{
"cell_type": "markdown",
"id": "0701d6db",
"metadata": {},
"source": [
"Краткую статистику по всем данным можно получить при помощи метода describe().\n",
"\n",
"Она будет посчитана только для тех признаков, которые представлены численно."
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "d0cde577",
"metadata": {},
"outputs": [
{
"data": {
"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>PassengerId</th>\n",
" <th>Survived</th>\n",
" <th>Pclass</th>\n",
" <th>Age</th>\n",
" <th>SibSp</th>\n",
" <th>Parch</th>\n",
" <th>Fare</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>891.000000</td>\n",
" <td>891.000000</td>\n",
" <td>891.000000</td>\n",
" <td>714.000000</td>\n",
" <td>891.000000</td>\n",
" <td>891.000000</td>\n",
" <td>891.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>446.000000</td>\n",
" <td>0.383838</td>\n",
" <td>2.308642</td>\n",
" <td>29.699118</td>\n",
" <td>0.523008</td>\n",
" <td>0.381594</td>\n",
" <td>32.204208</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>257.353842</td>\n",
" <td>0.486592</td>\n",
" <td>0.836071</td>\n",
" <td>14.526497</td>\n",
" <td>1.102743</td>\n",
" <td>0.806057</td>\n",
" <td>49.693429</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>1.000000</td>\n",
" <td>0.000000</td>\n",
" <td>1.000000</td>\n",
" <td>0.420000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>223.500000</td>\n",
" <td>0.000000</td>\n",
" <td>2.000000</td>\n",
" <td>20.125000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>7.910400</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>446.000000</td>\n",
" <td>0.000000</td>\n",
" <td>3.000000</td>\n",
" <td>28.000000</td>\n",
" <td>0.000000</td>\n",
" <td>0.000000</td>\n",
" <td>14.454200</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>668.500000</td>\n",
" <td>1.000000</td>\n",
" <td>3.000000</td>\n",
" <td>38.000000</td>\n",
" <td>1.000000</td>\n",
" <td>0.000000</td>\n",
" <td>31.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>891.000000</td>\n",
" <td>1.000000</td>\n",
" <td>3.000000</td>\n",
" <td>80.000000</td>\n",
" <td>8.000000</td>\n",
" <td>6.000000</td>\n",
" <td>512.329200</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" PassengerId Survived Pclass Age SibSp \\\n",
"count 891.000000 891.000000 891.000000 714.000000 891.000000 \n",
"mean 446.000000 0.383838 2.308642 29.699118 0.523008 \n",
"std 257.353842 0.486592 0.836071 14.526497 1.102743 \n",
"min 1.000000 0.000000 1.000000 0.420000 0.000000 \n",
"25% 223.500000 0.000000 2.000000 20.125000 0.000000 \n",
"50% 446.000000 0.000000 3.000000 28.000000 0.000000 \n",
"75% 668.500000 1.000000 3.000000 38.000000 1.000000 \n",
"max 891.000000 1.000000 3.000000 80.000000 8.000000 \n",
"\n",
" Parch Fare \n",
"count 891.000000 891.000000 \n",
"mean 0.381594 32.204208 \n",
"std 0.806057 49.693429 \n",
"min 0.000000 0.000000 \n",
"25% 0.000000 7.910400 \n",
"50% 0.000000 14.454200 \n",
"75% 0.000000 31.000000 \n",
"max 6.000000 512.329200 "
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.describe()"
]
},
{
"cell_type": "markdown",
"id": "e9c1c6b5",
"metadata": {},
"source": [
"Информацию по типам данных и количеству пропусков можно посмотреть при помощи info"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "964c9588",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 891 entries, 0 to 890\n",
"Data columns (total 12 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 PassengerId 891 non-null int64 \n",
" 1 Survived 891 non-null int64 \n",
" 2 Pclass 891 non-null int64 \n",
" 3 Name 891 non-null object \n",
" 4 Sex 891 non-null object \n",
" 5 Age 714 non-null float64\n",
" 6 SibSp 891 non-null int64 \n",
" 7 Parch 891 non-null int64 \n",
" 8 Ticket 891 non-null object \n",
" 9 Fare 891 non-null float64\n",
" 10 Cabin 204 non-null object \n",
" 11 Embarked 889 non-null object \n",
"dtypes: float64(2), int64(5), object(5)\n",
"memory usage: 83.7+ KB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "markdown",
"id": "13a039cc",
"metadata": {},
"source": [
"Можно применять различные встроенные методы к определенным признакам, обращаясь двумя равнозначными способами:"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "375462f9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.3838383838383838"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.Survived.mean()"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "a7fbc32b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.3838383838383838"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Survived'].mean()"
]
},
{
"cell_type": "markdown",
"id": "b33c70db",
"metadata": {},
"source": [
"### Задание\n",
"Выведите максимальный и минимальный возраст пассажиров"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5ef929a7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "bd46e44e",
"metadata": {},
"source": [
"### Задание\n",
"Воспользуйтесь встроенным методом value_counts для признака Pclass."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b38010e0",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "858da916",
"metadata": {},
"source": [
"Для получения конкретной строки можно использовать индексацию:"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "890e3a69",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"PassengerId 6\n",
"Survived 0\n",
"Pclass 3\n",
"Name Moran, Mr. James\n",
"Sex male\n",
"Age NaN\n",
"SibSp 0\n",
"Parch 0\n",
"Ticket 330877\n",
"Fare 8.4583\n",
"Cabin NaN\n",
"Embarked Q\n",
"Name: 5, dtype: object"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.iloc[5]"
]
},
{
"cell_type": "markdown",
"id": "6d365deb",
"metadata": {},
"source": [
"### Задание\n",
"Выведите номер билета у 120-го пассажира "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c8bea19",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "d024a508",
"metadata": {},
"source": [
"Возможно применение фильтрации для данных по какому-либо условию:"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "a9f9500d",
"metadata": {},
"outputs": [
{
"data": {
"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>PassengerId</th>\n",
" <th>Survived</th>\n",
" <th>Pclass</th>\n",
" <th>Name</th>\n",
" <th>Sex</th>\n",
" <th>Age</th>\n",
" <th>SibSp</th>\n",
" <th>Parch</th>\n",
" <th>Ticket</th>\n",
" <th>Fare</th>\n",
" <th>Cabin</th>\n",
" <th>Embarked</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>7</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>McCarthy, Mr. Timothy J</td>\n",
" <td>male</td>\n",
" <td>54.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>17463</td>\n",
" <td>51.8625</td>\n",
" <td>E46</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>12</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Bonnell, Miss. Elizabeth</td>\n",
" <td>female</td>\n",
" <td>58.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>113783</td>\n",
" <td>26.5500</td>\n",
" <td>C103</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>16</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>Hewlett, Mrs. (Mary D Kingcome)</td>\n",
" <td>female</td>\n",
" <td>55.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>248706</td>\n",
" <td>16.0000</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>34</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>Wheadon, Mr. Edward H</td>\n",
" <td>male</td>\n",
" <td>66.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>C.A. 24579</td>\n",
" <td>10.5000</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>54</th>\n",
" <td>55</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>Ostby, Mr. Engelhart Cornelius</td>\n",
" <td>male</td>\n",
" <td>65.0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>113509</td>\n",
" <td>61.9792</td>\n",
" <td>B30</td>\n",
" <td>C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>820</th>\n",
" <td>821</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Hays, Mrs. Charles Melville (Clara Jennings Gr...</td>\n",
" <td>female</td>\n",
" <td>52.0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>12749</td>\n",
" <td>93.5000</td>\n",
" <td>B69</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>829</th>\n",
" <td>830</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Stone, Mrs. George Nelson (Martha Evelyn)</td>\n",
" <td>female</td>\n",
" <td>62.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>113572</td>\n",
" <td>80.0000</td>\n",
" <td>B28</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>851</th>\n",
" <td>852</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Svensson, Mr. Johan</td>\n",
" <td>male</td>\n",
" <td>74.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>347060</td>\n",
" <td>7.7750</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>857</th>\n",
" <td>858</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Daly, Mr. Peter Denis</td>\n",
" <td>male</td>\n",
" <td>51.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>113055</td>\n",
" <td>26.5500</td>\n",
" <td>E17</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>879</th>\n",
" <td>880</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Potter, Mrs. Thomas Jr (Lily Alexenia Wilson)</td>\n",
" <td>female</td>\n",
" <td>56.0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>11767</td>\n",
" <td>83.1583</td>\n",
" <td>C50</td>\n",
" <td>C</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>64 rows × 12 columns</p>\n",
"</div>"
],
"text/plain": [
" PassengerId Survived Pclass \\\n",
"6 7 0 1 \n",
"11 12 1 1 \n",
"15 16 1 2 \n",
"33 34 0 2 \n",
"54 55 0 1 \n",
".. ... ... ... \n",
"820 821 1 1 \n",
"829 830 1 1 \n",
"851 852 0 3 \n",
"857 858 1 1 \n",
"879 880 1 1 \n",
"\n",
" Name Sex Age SibSp \\\n",
"6 McCarthy, Mr. Timothy J male 54.0 0 \n",
"11 Bonnell, Miss. Elizabeth female 58.0 0 \n",
"15 Hewlett, Mrs. (Mary D Kingcome) female 55.0 0 \n",
"33 Wheadon, Mr. Edward H male 66.0 0 \n",
"54 Ostby, Mr. Engelhart Cornelius male 65.0 0 \n",
".. ... ... ... ... \n",
"820 Hays, Mrs. Charles Melville (Clara Jennings Gr... female 52.0 1 \n",
"829 Stone, Mrs. George Nelson (Martha Evelyn) female 62.0 0 \n",
"851 Svensson, Mr. Johan male 74.0 0 \n",
"857 Daly, Mr. Peter Denis male 51.0 0 \n",
"879 Potter, Mrs. Thomas Jr (Lily Alexenia Wilson) female 56.0 0 \n",
"\n",
" Parch Ticket Fare Cabin Embarked \n",
"6 0 17463 51.8625 E46 S \n",
"11 0 113783 26.5500 C103 S \n",
"15 0 248706 16.0000 NaN S \n",
"33 0 C.A. 24579 10.5000 NaN S \n",
"54 1 113509 61.9792 B30 C \n",
".. ... ... ... ... ... \n",
"820 1 12749 93.5000 B69 S \n",
"829 0 113572 80.0000 B28 NaN \n",
"851 0 347060 7.7750 NaN S \n",
"857 0 113055 26.5500 E17 S \n",
"879 1 11767 83.1583 C50 C \n",
"\n",
"[64 rows x 12 columns]"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# посмотрим все данные пассажиров, которые старше 50\n",
"df[df.Age > 50]"
]
},
{
"cell_type": "markdown",
"id": "fd091601",
"metadata": {},
"source": [
"### Задание\n",
"Выведите имена всех мужчин в виде списка"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b52fd60b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "c2a8a119",
"metadata": {},
"source": [
"Можно использовать встроенные графики для отображения данных"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "d1066e4c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:>"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD5CAYAAADcDXXiAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAATvElEQVR4nO3df4xV533n8fcnOHFS0wS8jkcsWIVIKFt7rST1iG1kKRpKW7N1VPyPV0RuRCqv2D+83qzWUgX9Y6v+geRdyVUry14JmbRUpplFcSxQYiWxqGe7kVyTkDgl2GFNY9ZMIdDGP9rJRo5wv/vHHHZv8QxzuXOHmXn0fkmje85zn/Oc53sRnzk8995DqgpJUlves9gTkCQNn+EuSQ0y3CWpQYa7JDXIcJekBhnuktSg6+bqkOSjwH/vafoI8J+BP+3a1wOngX9TVW90x+wG7gfeAf5DVX39Sue46aabav369Vc/+85PfvITbrjhhoGPXypaqQOsZSlqpQ6wlkuOHTv2d1X14RmfrKq+f4AVwI+AXwD+K7Cra98F/Jdu+1bge8D1wAbgr4EVVxr3jjvuqPl47rnn5nX8UtFKHVXWshS1UkeVtVwCfLtmydWrXZbZAvx1Vf1vYBuwv2vfD9zTbW8Dxqvq7ap6FTgFbLrK80iS5uFqw3078MVue6SqzgF0jzd37WuBMz3HTHZtkqRrJNXn7QeSvA84C9xWVeeTvFlVq3qef6OqVid5DHi+qp7s2vcBz1TVU5eNtxPYCTAyMnLH+Pj4wEVMTU2xcuXKgY9fKlqpA6xlKWqlDrCWSzZv3nysqkZnfHK29ZrLf5hebvlGz/5JYE23vQY42W3vBnb39Ps68Mkrje2a+7RW6qiylqWolTqqrOUShrTm/hn+/5IMwGFgR7e9AzjU0749yfVJNgAbgaNXcR5J0jzN+VFIgCQ/B/wa8O96mh8GDia5H3gNuBegqk4kOQi8BFwEHqiqd4Y6a0nSFfUV7lX1f4B/dlnbj5n+9MxM/fc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4CDxQVe/Me6aSpL5dVbhX1QQw0W3/GNgyS789wJ55zk2SNCC/oSpJDTLcJalBhrskNchwl6QGGe6S1CDDXZIaZLhLUoMMd0lqkOEuSQ0y3CWpQYa7JDXIcJekBhnuktQgw12SGmS4S1KDDHdJapDhLkkNMtwlqUGGuyQ1yHCXpAYZ7pLUoDnDPcn7kxxN8r0kJ5L8ftd+Y5Jnk7zSPa7uOWZ3klNJTia5ayELkCS9Wz9X7m8Dv1JVHwM+DmxN8svALuBIVW0EjnT7JLkV2A7cBmwFHk+yYgHmLkmaxZzhXtOmut33dj8FbAP2d+37gXu67W3AeFW9XVWvAqeATcOctCTpyvpac0+yIsmLwAXg2ap6ARipqnMA3ePNXfe1wJmewye7NknSNZKq6r9zsgp4GngQ+GZVrep57o2qWp3kMeD5qnqya98HPFNVT1021k5gJ8DIyMgd4+PjAxdx4fW3OP/TgQ8f2O1rPzTU8aampli5cuVQx1ws1rL0tFIHWMslmzdvPlZVozM9d93VDFRVbyaZYHot/XySNVV1Lskapq/qYfpK/Zaew9YBZ2cYay+wF2B0dLTGxsauZir/xKMHDvHI8asqZShO3zc21PEmJiaYz+uwlFjL0tNKHWAt/ejn0zIf7q7YSfIB4FeBHwCHgR1dtx3AoW77MLA9yfVJNgAbgaNDnrck6Qr6udxdA+zvPvHyHuBgVX0lyfPAwST3A68B9wJU1YkkB4GXgIvAA1X1zsJMX5I0kznDvar+CvjEDO0/BrbMcsweYM+8ZydJGojfUJWkBhnuktQgw12SGmS4S1KDDHdJapDhLkkNMtwlqUGGuyQ1yHCXpAYZ7pLUIMNdkhpkuEtSgwx3SWqQ4S5JDTLcJalBhrskNchwl6QGGe6S1CDDXZIaZLh
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"df.Parch.hist()"
]
},
{
"cell_type": "markdown",
"id": "92e95229",
"metadata": {},
"source": [
"### Задание\n",
"Постройте гистограмму на которой будет отображено количество людей в каждом из классов обслуживания"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f3b54a84",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "1ed5afe4",
"metadata": {},
"source": [
"Из датафрейма можно выделять подвыборки и делать их самостоятельными датафреймами:"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "b7c07681",
"metadata": {},
"outputs": [
{
"data": {
"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>PassengerId</th>\n",
" <th>Survived</th>\n",
" <th>Pclass</th>\n",
" <th>Name</th>\n",
" <th>Sex</th>\n",
" <th>Age</th>\n",
" <th>SibSp</th>\n",
" <th>Parch</th>\n",
" <th>Ticket</th>\n",
" <th>Fare</th>\n",
" <th>Cabin</th>\n",
" <th>Embarked</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
" <td>female</td>\n",
" <td>38.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>PC 17599</td>\n",
" <td>71.2833</td>\n",
" <td>C85</td>\n",
" <td>C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>Heikkinen, Miss. Laina</td>\n",
" <td>female</td>\n",
" <td>26.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>STON/O2. 3101282</td>\n",
" <td>7.9250</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
" <td>female</td>\n",
" <td>35.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>113803</td>\n",
" <td>53.1000</td>\n",
" <td>C123</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>9</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)</td>\n",
" <td>female</td>\n",
" <td>27.0</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>347742</td>\n",
" <td>11.1333</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>10</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>Nasser, Mrs. Nicholas (Adele Achem)</td>\n",
" <td>female</td>\n",
" <td>14.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>237736</td>\n",
" <td>30.0708</td>\n",
" <td>NaN</td>\n",
" <td>C</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>880</th>\n",
" <td>881</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>Shelley, Mrs. William (Imanita Parrish Hall)</td>\n",
" <td>female</td>\n",
" <td>25.0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>230433</td>\n",
" <td>26.0000</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>882</th>\n",
" <td>883</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Dahlberg, Miss. Gerda Ulrika</td>\n",
" <td>female</td>\n",
" <td>22.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>7552</td>\n",
" <td>10.5167</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>885</th>\n",
" <td>886</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Rice, Mrs. William (Margaret Norton)</td>\n",
" <td>female</td>\n",
" <td>39.0</td>\n",
" <td>0</td>\n",
" <td>5</td>\n",
" <td>382652</td>\n",
" <td>29.1250</td>\n",
" <td>NaN</td>\n",
" <td>Q</td>\n",
" </tr>\n",
" <tr>\n",
" <th>887</th>\n",
" <td>888</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Graham, Miss. Margaret Edith</td>\n",
" <td>female</td>\n",
" <td>19.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>112053</td>\n",
" <td>30.0000</td>\n",
" <td>B42</td>\n",
" <td>S</td>\n",
" </tr>\n",
" <tr>\n",
" <th>888</th>\n",
" <td>889</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Johnston, Miss. Catherine Helen \"Carrie\"</td>\n",
" <td>female</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>W./C. 6607</td>\n",
" <td>23.4500</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>314 rows × 12 columns</p>\n",
"</div>"
],
"text/plain": [
" PassengerId Survived Pclass \\\n",
"1 2 1 1 \n",
"2 3 1 3 \n",
"3 4 1 1 \n",
"8 9 1 3 \n",
"9 10 1 2 \n",
".. ... ... ... \n",
"880 881 1 2 \n",
"882 883 0 3 \n",
"885 886 0 3 \n",
"887 888 1 1 \n",
"888 889 0 3 \n",
"\n",
" Name Sex Age SibSp \\\n",
"1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n",
"2 Heikkinen, Miss. Laina female 26.0 0 \n",
"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n",
"8 Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) female 27.0 0 \n",
"9 Nasser, Mrs. Nicholas (Adele Achem) female 14.0 1 \n",
".. ... ... ... ... \n",
"880 Shelley, Mrs. William (Imanita Parrish Hall) female 25.0 0 \n",
"882 Dahlberg, Miss. Gerda Ulrika female 22.0 0 \n",
"885 Rice, Mrs. William (Margaret Norton) female 39.0 0 \n",
"887 Graham, Miss. Margaret Edith female 19.0 0 \n",
"888 Johnston, Miss. Catherine Helen \"Carrie\" female NaN 1 \n",
"\n",
" Parch Ticket Fare Cabin Embarked \n",
"1 0 PC 17599 71.2833 C85 C \n",
"2 0 STON/O2. 3101282 7.9250 NaN S \n",
"3 0 113803 53.1000 C123 S \n",
"8 2 347742 11.1333 NaN S \n",
"9 0 237736 30.0708 NaN C \n",
".. ... ... ... ... ... \n",
"880 1 230433 26.0000 NaN S \n",
"882 0 7552 10.5167 NaN S \n",
"885 5 382652 29.1250 NaN Q \n",
"887 0 112053 30.0000 B42 S \n",
"888 2 W./C. 6607 23.4500 NaN S \n",
"\n",
"[314 rows x 12 columns]"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Выделим в отдельную таблицу всех женщин\n",
"df_2 = df[df.Sex == 'female']\n",
"df_2"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "15eef0ed",
"metadata": {},
"outputs": [
{
"data": {
"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>Name</th>\n",
" <th>Age</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Braund, Mr. Owen Harris</td>\n",
" <td>22.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
" <td>38.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Heikkinen, Miss. Laina</td>\n",
" <td>26.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
" <td>35.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Allen, Mr. William Henry</td>\n",
" <td>35.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>886</th>\n",
" <td>Montvila, Rev. Juozas</td>\n",
" <td>27.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>887</th>\n",
" <td>Graham, Miss. Margaret Edith</td>\n",
" <td>19.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>888</th>\n",
" <td>Johnston, Miss. Catherine Helen \"Carrie\"</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>889</th>\n",
" <td>Behr, Mr. Karl Howell</td>\n",
" <td>26.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>890</th>\n",
" <td>Dooley, Mr. Patrick</td>\n",
" <td>32.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>891 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" Name Age\n",
"0 Braund, Mr. Owen Harris 22.0\n",
"1 Cumings, Mrs. John Bradley (Florence Briggs Th... 38.0\n",
"2 Heikkinen, Miss. Laina 26.0\n",
"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) 35.0\n",
"4 Allen, Mr. William Henry 35.0\n",
".. ... ...\n",
"886 Montvila, Rev. Juozas 27.0\n",
"887 Graham, Miss. Margaret Edith 19.0\n",
"888 Johnston, Miss. Catherine Helen \"Carrie\" NaN\n",
"889 Behr, Mr. Karl Howell 26.0\n",
"890 Dooley, Mr. Patrick 32.0\n",
"\n",
"[891 rows x 2 columns]"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Выделим датафрейм хранящий только имена и возраст\n",
"df_3 = df[['Name', 'Age']]\n",
"df_3"
]
},
{
"cell_type": "markdown",
"id": "985f01cf",
"metadata": {},
"source": [
"### Задание\n",
"Создайте датафрейм где будут поля Name и Survived для пассажиров без детей"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b462754",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "c73eba53",
"metadata": {},
"source": [
"Для преобразования значений столбца можно применять метод .apply с указанием в нем функции, применяемой к значению каждой строки. В данном примере применяется анонимная функция (лямбда-функция)."
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "4d58666a",
"metadata": {},
"outputs": [
{
"data": {
"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>PassengerId</th>\n",
" <th>Survived</th>\n",
" <th>Pclass</th>\n",
" <th>Name</th>\n",
" <th>Sex</th>\n",
" <th>Age</th>\n",
" <th>SibSp</th>\n",
" <th>Parch</th>\n",
" <th>Ticket</th>\n",
" <th>Fare</th>\n",
" <th>Cabin</th>\n",
" <th>Embarked</th>\n",
" <th>isAdult</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Braund, Mr. Owen Harris</td>\n",
" <td>male</td>\n",
" <td>22.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>A/5 21171</td>\n",
" <td>7.2500</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
" <td>female</td>\n",
" <td>38.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>PC 17599</td>\n",
" <td>71.2833</td>\n",
" <td>C85</td>\n",
" <td>C</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>Heikkinen, Miss. Laina</td>\n",
" <td>female</td>\n",
" <td>26.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>STON/O2. 3101282</td>\n",
" <td>7.9250</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
" <td>female</td>\n",
" <td>35.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>113803</td>\n",
" <td>53.1000</td>\n",
" <td>C123</td>\n",
" <td>S</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Allen, Mr. William Henry</td>\n",
" <td>male</td>\n",
" <td>35.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>373450</td>\n",
" <td>8.0500</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>886</th>\n",
" <td>887</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>Montvila, Rev. Juozas</td>\n",
" <td>male</td>\n",
" <td>27.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>211536</td>\n",
" <td>13.0000</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>887</th>\n",
" <td>888</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Graham, Miss. Margaret Edith</td>\n",
" <td>female</td>\n",
" <td>19.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>112053</td>\n",
" <td>30.0000</td>\n",
" <td>B42</td>\n",
" <td>S</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>888</th>\n",
" <td>889</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Johnston, Miss. Catherine Helen \"Carrie\"</td>\n",
" <td>female</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>W./C. 6607</td>\n",
" <td>23.4500</td>\n",
" <td>NaN</td>\n",
" <td>S</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>889</th>\n",
" <td>890</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>Behr, Mr. Karl Howell</td>\n",
" <td>male</td>\n",
" <td>26.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>111369</td>\n",
" <td>30.0000</td>\n",
" <td>C148</td>\n",
" <td>C</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>890</th>\n",
" <td>891</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>Dooley, Mr. Patrick</td>\n",
" <td>male</td>\n",
" <td>32.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>370376</td>\n",
" <td>7.7500</td>\n",
" <td>NaN</td>\n",
" <td>Q</td>\n",
" <td>True</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>891 rows × 13 columns</p>\n",
"</div>"
],
"text/plain": [
" PassengerId Survived Pclass \\\n",
"0 1 0 3 \n",
"1 2 1 1 \n",
"2 3 1 3 \n",
"3 4 1 1 \n",
"4 5 0 3 \n",
".. ... ... ... \n",
"886 887 0 2 \n",
"887 888 1 1 \n",
"888 889 0 3 \n",
"889 890 1 1 \n",
"890 891 0 3 \n",
"\n",
" Name Sex Age SibSp \\\n",
"0 Braund, Mr. Owen Harris male 22.0 1 \n",
"1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n",
"2 Heikkinen, Miss. Laina female 26.0 0 \n",
"3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n",
"4 Allen, Mr. William Henry male 35.0 0 \n",
".. ... ... ... ... \n",
"886 Montvila, Rev. Juozas male 27.0 0 \n",
"887 Graham, Miss. Margaret Edith female 19.0 0 \n",
"888 Johnston, Miss. Catherine Helen \"Carrie\" female NaN 1 \n",
"889 Behr, Mr. Karl Howell male 26.0 0 \n",
"890 Dooley, Mr. Patrick male 32.0 0 \n",
"\n",
" Parch Ticket Fare Cabin Embarked isAdult \n",
"0 0 A/5 21171 7.2500 NaN S True \n",
"1 0 PC 17599 71.2833 C85 C True \n",
"2 0 STON/O2. 3101282 7.9250 NaN S True \n",
"3 0 113803 53.1000 C123 S True \n",
"4 0 373450 8.0500 NaN S True \n",
".. ... ... ... ... ... ... \n",
"886 0 211536 13.0000 NaN S True \n",
"887 0 112053 30.0000 B42 S True \n",
"888 2 W./C. 6607 23.4500 NaN S False \n",
"889 0 111369 30.0000 C148 C True \n",
"890 0 370376 7.7500 NaN Q True \n",
"\n",
"[891 rows x 13 columns]"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['isAdult'] = df['Age'].apply(lambda x: x > 18)\n",
"df"
]
},
{
"cell_type": "markdown",
"id": "51e5b6be",
"metadata": {},
"source": [
"### Задание\n",
"Посчитайте среднее значение цены билета на корабле. Введите новый столбец, который будет показывать дешевле или дороже средней цены был купленный билет у каждого человека. Можете заполнить поля значениями True/False или строчными представлениями \"дешевле\"/\"дороже\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "167386f6",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}