{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "05f9e335-cc95-41f5-b676-1973cbdfcc2b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, World!\n"
     ]
    }
   ],
   "source": [
    "# Напечатаем \"Hello, World!\"\n",
    "print(\"Hello, World!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6f59955-12db-4a2c-b89e-fe2705812745",
   "metadata": {},
   "source": [
    "# Заголовок 1\n",
    "## Заголовок 2\n",
    "\n",
    "- Список\n",
    "- Элементы\n",
    "\n",
    "**Жирный текст**, *курсив*.\n",
    "\n",
    "Формула: $E=mc^2$\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "81bbe66d-663a-4b9f-bb3d-662784e80125",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2 4 6]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "x = np.array([1, 2, 3])\n",
    "print(x * 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1218f6e3-74f7-451a-b1c9-6b8a93b8afda",
   "metadata": {},
   "source": [
    "# Анализ данных\n",
    "## Загрузка данных\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15d64548-c726-4dc4-b7a5-58d6dfcaf0ff",
   "metadata": {},
   "source": [
    "## Работа с pandas и numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4f1bd4ed-5c99-441f-b34b-25126f6da486",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Первый взгляд на данные:\n",
      "      Имя  Возраст  Баллы\n",
      "0    Анна       21     89\n",
      "1   Борис       22     76\n",
      "2  Виктор       23     95\n",
      "3  Галина       24     82\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 4 entries, 0 to 3\n",
      "Data columns (total 3 columns):\n",
      " #   Column   Non-Null Count  Dtype \n",
      "---  ------   --------------  ----- \n",
      " 0   Имя      4 non-null      object\n",
      " 1   Возраст  4 non-null      int64 \n",
      " 2   Баллы    4 non-null      int64 \n",
      "dtypes: int64(2), object(1)\n",
      "memory usage: 228.0+ bytes\n",
      "None\n",
      "         Возраст      Баллы\n",
      "count   4.000000   4.000000\n",
      "mean   22.500000  85.500000\n",
      "std     1.290994   8.266398\n",
      "min    21.000000  76.000000\n",
      "25%    21.750000  80.500000\n",
      "50%    22.500000  85.500000\n",
      "75%    23.250000  90.500000\n",
      "max    24.000000  95.000000\n",
      "Имя        0\n",
      "Возраст    0\n",
      "Баллы      0\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# Создадим DataFrame\n",
    "data = {\n",
    "    \"Имя\": [\"Анна\", \"Борис\", \"Виктор\", \"Галина\"],\n",
    "    \"Возраст\": [21, 22, 23, 24],\n",
    "    \"Баллы\": [89, 76, 95, 82]\n",
    "}\n",
    "df = pd.DataFrame(data)\n",
    "\n",
    "print(\"Первый взгляд на данные:\")\n",
    "print(df.head())\n",
    "print(df.info())\n",
    "print(df.describe())\n",
    "print(df.isnull().sum())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "75ac88aa-83f5-45f3-868a-3d9e94bec938",
   "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>Имя</th>\n",
       "      <th>Возраст</th>\n",
       "      <th>Баллы</th>\n",
       "      <th>Новый_столбец</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Анна</td>\n",
       "      <td>21</td>\n",
       "      <td>89</td>\n",
       "      <td>97.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Борис</td>\n",
       "      <td>22</td>\n",
       "      <td>76</td>\n",
       "      <td>83.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Виктор</td>\n",
       "      <td>23</td>\n",
       "      <td>95</td>\n",
       "      <td>104.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Галина</td>\n",
       "      <td>24</td>\n",
       "      <td>82</td>\n",
       "      <td>90.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Имя  Возраст  Баллы  Новый_столбец\n",
       "0    Анна       21     89           97.9\n",
       "1   Борис       22     76           83.6\n",
       "2  Виктор       23     95          104.5\n",
       "3  Галина       24     82           90.2"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"Новый_столбец\"] = df[\"Баллы\"] * 1.1\n",
    "df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "bcacaa27-7bf4-4eac-bb1d-1380642ec96f",
   "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 tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">Баллы</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>mean</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Категория</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>92.0</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>79.0</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Баллы    \n",
       "           mean max\n",
       "Категория          \n",
       "A          92.0  95\n",
       "B          79.0  82"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Добавим категории для группировки\n",
    "df[\"Категория\"] = [\"A\", \"B\", \"A\", \"B\"]\n",
    "grouped = df.groupby(\"Категория\").agg({\"Баллы\": [\"mean\", \"max\"]})\n",
    "grouped"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8a35f9d7-8d0e-487e-96d5-f97dfbf51862",
   "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>Имя</th>\n",
       "      <th>Возраст</th>\n",
       "      <th>Баллы</th>\n",
       "      <th>Новый_столбец</th>\n",
       "      <th>Категория</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Борис</td>\n",
       "      <td>22</td>\n",
       "      <td>76</td>\n",
       "      <td>83.6</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Виктор</td>\n",
       "      <td>23</td>\n",
       "      <td>95</td>\n",
       "      <td>104.5</td>\n",
       "      <td>A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Галина</td>\n",
       "      <td>24</td>\n",
       "      <td>82</td>\n",
       "      <td>90.2</td>\n",
       "      <td>B</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Имя  Возраст  Баллы  Новый_столбец Категория\n",
       "1   Борис       22     76           83.6         B\n",
       "2  Виктор       23     95          104.5         A\n",
       "3  Галина       24     82           90.2         B"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df[\"Возраст\"] > 21]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5dc63812-f408-43e2-8aa6-f74e33869778",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Сумма элементов массива: 15\n",
      "Среднее значение: 3.0\n",
      "Медиана: 3.0\n",
      "Стандартное отклонение: 1.4142135623730951\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "arr = np.array([1, 2, 3, 4, 5])\n",
    "print(\"Сумма элементов массива:\", np.sum(arr))\n",
    "print(\"Среднее значение:\", np.mean(arr))\n",
    "print(\"Медиана:\", np.median(arr))\n",
    "print(\"Стандартное отклонение:\", np.std(arr))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6be7edd1-323b-49e4-891e-b0780ca78aad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Матрица:\n",
      " [[1 2]\n",
      " [3 4]]\n",
      "Произведение матриц:\n",
      " [[ 7 10]\n",
      " [15 22]]\n"
     ]
    }
   ],
   "source": [
    "# Создаем матрицу 2x2\n",
    "matrix = np.array([[1, 2], [3, 4]])\n",
    "print(\"Матрица:\\n\", matrix)\n",
    "print(\"Произведение матриц:\\n\", np.dot(matrix, matrix))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "49252a5a-24dc-41fa-9bf1-0b945fe7c370",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Равномерные значения: [ 0.   2.5  5.   7.5 10. ]\n",
      "Случайные числа: [-0.99645984 -2.05825786 -0.10075374 -0.65218543 -0.78365857]\n"
     ]
    }
   ],
   "source": [
    "# Генерируем 5 равномерно распределенных чисел от 0 до 10\n",
    "linear_space = np.linspace(0, 10, 5)\n",
    "print(\"Равномерные значения:\", linear_space)\n",
    "\n",
    "# Генерируем 5 случайных чисел из стандартного нормального распределения\n",
    "random_numbers = np.random.randn(5)\n",
    "print(\"Случайные числа:\", random_numbers)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a391c052-926b-445a-846c-b70df0fdd7d9",
   "metadata": {},
   "source": [
    "## Визуализация данных\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "bec8964a-9654-4fa9-8ab5-19ee0395b7a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 39632 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "x = np.linspace(0, 10, 100)\n",
    "y = np.sin(x)\n",
    "\n",
    "plt.plot(x, y, label='sin(x)')\n",
    "plt.xlabel(\"X\")\n",
    "plt.ylabel(\"Y\")\n",
    "plt.title(\"График синуса\")\n",
    "plt.legend()\n",
    "plt.grid()\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "cfdd1fb0-e746-46f6-b204-7badfeee549b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 54024 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "x = np.linspace(0, 10, 100)\n",
    "y_sin = np.sin(x)\n",
    "y_cos = np.cos(x)\n",
    "\n",
    "# Строим графики с разными цветами и подписями\n",
    "plt.plot(x, y_sin, color='red', label='sin(x)')\n",
    "plt.plot(x, y_cos, color='blue', linestyle='--', label='cos(x)')\n",
    "\n",
    "# Добавляем подписи и легенду\n",
    "plt.xlabel(\"Ось X\")\n",
    "plt.ylabel(\"Ось Y\")\n",
    "plt.title(\"Графики синуса и косинуса\")\n",
    "plt.legend()\n",
    "plt.grid(True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4f4130c2-d61f-492e-905c-a829936157c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 10336 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 20376 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 14892 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Столбчатая диаграмма (bar)\n",
    "plt.bar([\"A\", \"B\", \"C\"], [3, 7, 2], color=['red', 'green', 'blue'])\n",
    "plt.title(\"Пример bar-графика\")\n",
    "plt.show()\n",
    "\n",
    "# Точечный график (scatter)\n",
    "x = np.random.rand(50)\n",
    "y = x + np.random.normal(0, 0.1, 50)\n",
    "plt.scatter(x, y, alpha=0.6)\n",
    "plt.title(\"Точечный график\")\n",
    "plt.show()\n",
    "\n",
    "# Гистограмма (hist)\n",
    "data = np.random.randn(1000)\n",
    "plt.hist(data, bins=30, edgecolor='black')\n",
    "plt.title(\"Гистограмма распределения\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2c54ad21-ccc1-4654-a675-24df437ceae3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 15340 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "\n",
    "df[\"Категория\"] = [\"A\", \"B\", \"A\", \"B\"] # догадайтесь откуда df и её содержимое взялось\n",
    "sns.boxplot(x=\"Категория\", y=\"Баллы\", data=df)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "1e0a02bf-009f-4220-aa71-4344db9dbfd3",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\alexe\\AppData\\Local\\Temp\\ipykernel_9644\\225627229.py:16: FutureWarning: \n",
      "\n",
      "Passing `palette` without assigning `hue` is deprecated and will be removed in v0.14.0. Assign the `x` variable to `hue` and set `legend=False` for the same effect.\n",
      "\n",
      "  sns.boxplot(x=\"Категория\", y=\"Баллы\", data=df, palette=\"pastel\")\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 22044 characters]",
      "text/plain": [
       "<Figure size 800x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 23376 characters]",
      "text/plain": [
       "<Figure size 800x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 29404 characters]",
      "text/plain": [
       "<Figure size 800x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Матрица графиков для всех числовых данных:\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 32652 characters]",
      "text/plain": [
       "<Figure size 720x600 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 22912 characters]",
      "text/plain": [
       "<Figure size 600x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "\n",
    "# Создаем DataFrame (если он еще не создан)\n",
    "data = {\n",
    "    \"Имя\": [\"Анна\", \"Борис\", \"Виктор\", \"Галина\"],\n",
    "    \"Возраст\": [21, 22, 23, 24],\n",
    "    \"Баллы\": [89, 76, 95, 82]\n",
    "}\n",
    "df = pd.DataFrame(data)\n",
    "df[\"Категория\"] = [\"A\", \"B\", \"A\", \"B\"]  # Добавляем категории\n",
    "\n",
    "# 1. Boxplot (ящик с усами)\n",
    "plt.figure(figsize=(8, 5))\n",
    "sns.boxplot(x=\"Категория\", y=\"Баллы\", data=df, palette=\"pastel\")\n",
    "plt.title(\"Распределение баллов по категориям\")\n",
    "plt.show()\n",
    "\n",
    "# 2. Histplot (гистограмма с распределением)\n",
    "plt.figure(figsize=(8, 5))\n",
    "sns.histplot(data=df, x=\"Баллы\", kde=True, bins=10, color=\"skyblue\")\n",
    "plt.title(\"Распределение баллов студентов\")\n",
    "plt.xlabel(\"Баллы\")\n",
    "plt.ylabel(\"Количество\")\n",
    "plt.show()\n",
    "\n",
    "# 3. Scatterplot (точечный график)\n",
    "plt.figure(figsize=(8, 5))\n",
    "sns.scatterplot(data=df, x=\"Возраст\", y=\"Баллы\", hue=\"Категория\", \n",
    "                s=150, palette=\"Set2\")\n",
    "plt.title(\"Зависимость баллов от возраста\")\n",
    "plt.grid(True)\n",
    "plt.show()\n",
    "\n",
    "# 4. Pairplot (матрица графиков)\n",
    "print(\"Матрица графиков для всех числовых данных:\")\n",
    "sns.pairplot(df[[\"Возраст\", \"Баллы\"]], height=3, aspect=1.2)\n",
    "plt.suptitle(\"Парные зависимости\", y=1.02)\n",
    "plt.show()\n",
    "\n",
    "# 5. Heatmap (тепловая карта корреляций)\n",
    "plt.figure(figsize=(6, 4))\n",
    "corr_matrix = df[[\"Возраст\", \"Баллы\"]].corr()\n",
    "sns.heatmap(corr_matrix, annot=True, cmap=\"coolwarm\", \n",
    "            fmt=\".2f\", linewidths=.5)\n",
    "plt.title(\"Корреляция между возрастом и баллами\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ae6852f-2862-4722-a636-dcf9ed421c68",
   "metadata": {},
   "source": [
    "## Прогресс-бар с tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "e18e589e-558c-4c51-96ba-b15a6199b795",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:01<00:00, 94.75it/s]\n"
     ]
    }
   ],
   "source": [
    "from tqdm import tqdm\n",
    "import time\n",
    "\n",
    "for i in tqdm(range(100)):\n",
    "    time.sleep(0.01)  # Симуляция долгого процесса"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "8e758a01-d801-48d0-a8bc-2685fc54b995",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Обработка данных: 100%|███████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:02<00:00, 48.36it/s]\n",
      "100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:00<00:00,  9.74it/s]\n"
     ]
    }
   ],
   "source": [
    "from tqdm import tqdm\n",
    "import time\n",
    "\n",
    "# Простой прогресс-бар\n",
    "for i in tqdm(range(100), desc=\"Обработка данных\"):\n",
    "    time.sleep(0.02)  # Имитация долгой операции\n",
    "    \n",
    "# Прогресс-бар для DataFrame\n",
    "for index, row in tqdm(df.iterrows(), total=len(df)):\n",
    "    time.sleep(0.1)  # Имитация обработки строк"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6f884906-bec9-440f-8385-4df02626b286",
   "metadata": {},
   "source": [
    "## Самостоятельное задание"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "26a497ff-d072-4cf5-b5cd-12bd9e1bc33f",
   "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>Survived</th>\n",
       "      <th>Pclass</th>\n",
       "      <th>Name</th>\n",
       "      <th>Sex</th>\n",
       "      <th>Age</th>\n",
       "      <th>Siblings/Spouses Aboard</th>\n",
       "      <th>Parents/Children Aboard</th>\n",
       "      <th>Fare</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Mr. Owen Harris Braund</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Mrs. John Bradley (Florence Briggs Thayer) Cum...</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>Miss. Laina Heikkinen</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Mrs. Jacques Heath (Lily May Peel) Futrelle</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Mr. William Henry Allen</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.0500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Survived  Pclass                                               Name  \\\n",
       "0         0       3                             Mr. Owen Harris Braund   \n",
       "1         1       1  Mrs. John Bradley (Florence Briggs Thayer) Cum...   \n",
       "2         1       3                              Miss. Laina Heikkinen   \n",
       "3         1       1        Mrs. Jacques Heath (Lily May Peel) Futrelle   \n",
       "4         0       3                            Mr. William Henry Allen   \n",
       "\n",
       "      Sex   Age  Siblings/Spouses Aboard  Parents/Children Aboard     Fare  \n",
       "0    male  22.0                        1                        0   7.2500  \n",
       "1  female  38.0                        1                        0  71.2833  \n",
       "2  female  26.0                        0                        0   7.9250  \n",
       "3  female  35.0                        1                        0  53.1000  \n",
       "4    male  35.0                        0                        0   8.0500  "
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# Для CSV\n",
    "df = pd.read_csv('titanic.csv')\n",
    "\n",
    "# Просмотр первых строк\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "5590d93c-66b8-458f-b44e-ac316ed23600",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 887 entries, 0 to 886\n",
      "Data columns (total 8 columns):\n",
      " #   Column                   Non-Null Count  Dtype  \n",
      "---  ------                   --------------  -----  \n",
      " 0   Survived                 887 non-null    int64  \n",
      " 1   Pclass                   887 non-null    int64  \n",
      " 2   Name                     887 non-null    object \n",
      " 3   Sex                      887 non-null    object \n",
      " 4   Age                      887 non-null    float64\n",
      " 5   Siblings/Spouses Aboard  887 non-null    int64  \n",
      " 6   Parents/Children Aboard  887 non-null    int64  \n",
      " 7   Fare                     887 non-null    float64\n",
      "dtypes: float64(2), int64(4), object(2)\n",
      "memory usage: 55.6+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()  # Типы данных, количество значений"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "b5704514-567b-4bad-be84-06401d193f54",
   "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>Survived</th>\n",
       "      <th>Pclass</th>\n",
       "      <th>Age</th>\n",
       "      <th>Siblings/Spouses Aboard</th>\n",
       "      <th>Parents/Children Aboard</th>\n",
       "      <th>Fare</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>887.000000</td>\n",
       "      <td>887.000000</td>\n",
       "      <td>887.000000</td>\n",
       "      <td>887.000000</td>\n",
       "      <td>887.000000</td>\n",
       "      <td>887.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.385569</td>\n",
       "      <td>2.305524</td>\n",
       "      <td>29.471443</td>\n",
       "      <td>0.525366</td>\n",
       "      <td>0.383315</td>\n",
       "      <td>32.30542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.487004</td>\n",
       "      <td>0.836662</td>\n",
       "      <td>14.121908</td>\n",
       "      <td>1.104669</td>\n",
       "      <td>0.807466</td>\n",
       "      <td>49.78204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\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.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>20.250000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>7.92500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\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.45420</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\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.13750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\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.32920</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         Survived      Pclass         Age  Siblings/Spouses Aboard  \\\n",
       "count  887.000000  887.000000  887.000000               887.000000   \n",
       "mean     0.385569    2.305524   29.471443                 0.525366   \n",
       "std      0.487004    0.836662   14.121908                 1.104669   \n",
       "min      0.000000    1.000000    0.420000                 0.000000   \n",
       "25%      0.000000    2.000000   20.250000                 0.000000   \n",
       "50%      0.000000    3.000000   28.000000                 0.000000   \n",
       "75%      1.000000    3.000000   38.000000                 1.000000   \n",
       "max      1.000000    3.000000   80.000000                 8.000000   \n",
       "\n",
       "       Parents/Children Aboard       Fare  \n",
       "count               887.000000  887.00000  \n",
       "mean                  0.383315   32.30542  \n",
       "std                   0.807466   49.78204  \n",
       "min                   0.000000    0.00000  \n",
       "25%                   0.000000    7.92500  \n",
       "50%                   0.000000   14.45420  \n",
       "75%                   0.000000   31.13750  \n",
       "max                   6.000000  512.32920  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe()  # Среднее, мин/макс, квантили для числовых столбцов"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7b484acb-8ac5-4271-a519-448b50a767d9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Survived                   0\n",
       "Pclass                     0\n",
       "Name                       0\n",
       "Sex                        0\n",
       "Age                        0\n",
       "Siblings/Spouses Aboard    0\n",
       "Parents/Children Aboard    0\n",
       "Fare                       0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.isnull().sum()  # Количество пропусков в каждом столбце"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "20226291-c7ea-4528-8b98-4914e02a24b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33720 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "sns.histplot(data=df, x='Age', kde=True, bins=20)\n",
    "plt.title('Распределение возраста')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "ce7270d7-7ac5-4f24-a78d-64ad477db6aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 19356 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.boxplot(data=df, x='Pclass', y='Fare')\n",
    "plt.title('Стоимость билета по классам')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "578c7d69-a172-4efa-b4cc-ea90890977ea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 78032 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.scatterplot(data=df, x='Age', y='Fare', hue='Survived')\n",
    "plt.title('Возраст vs Стоимость билета (с выживанием)')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9833271f-8bee-4620-b85d-cc049aedc82a",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████████████████████████████████████████████████████████████████████████████████████████████████| 887/887 [00:00<00:00, 295359.45it/s]\n"
     ]
    }
   ],
   "source": [
    "from tqdm import tqdm\n",
    "tqdm.pandas()  # Активация для pandas\n",
    "\n",
    "# Пример: применение функции к столбцу с прогресс-баром\n",
    "df['new_column'] = df['Age'].progress_apply(lambda x: x * 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d842e2b8-6cfe-4e2a-a4e3-d203d602563e",
   "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.12.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
