2заданиефулл

This commit is contained in:
Егор Сидоров 2026-04-25 17:52:08 +03:00
parent 9ed1755ce4
commit 39bef44953
5 changed files with 889 additions and 0 deletions

115
matplotlib.ipynb Normal file

File diff suppressed because one or more lines are too long

119
numpy.ipynb Normal file
View File

@ -0,0 +1,119 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a2f486bd-5b87-4e0f-9327-2ba680c00ebb",
"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": 2,
"id": "896a8a44-ea62-4a5c-97ba-d1d4edc1d694",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Двумерный массив (матрица):\n",
"[[1 2]\n",
" [3 4]]\n"
]
}
],
"source": [
"matrix = np.array([[1, 2], [3, 4]])\n",
"print(\"Двумерный массив (матрица):\")\n",
"print(matrix)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ce9bcbd6-a927-4e29-9206-32172f24299f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Массив через linspace: [ 0. 1.11111111 2.22222222 3.33333333 4.44444444 5.55555556\n",
" 6.66666667 7.77777778 8.88888889 10. ]\n",
"\n",
"Случайные числа:\n",
" [[-0.46721747 0.42148654]\n",
" [ 1.34381602 0.67923817]]\n",
"\n",
"Результат умножения векторов (dot): 11\n"
]
}
],
"source": [
"# 1. Создаем 10 чисел от 0 до 10 с равным шагом\n",
"line = np.linspace(0, 10, 10)\n",
"print(\"Массив через linspace:\", line)\n",
"\n",
"# 2. Генерируем случайные числа (матрица 2x2)\n",
"rand_arr = np.random.randn(2, 2)\n",
"print(\"\\nСлучайные числа:\\n\", rand_arr)\n",
"\n",
"# 3. Скалярное произведение векторов (np.dot)\n",
"v1 = np.array([1, 2])\n",
"v2 = np.array([3, 4])\n",
"result = np.dot(v1, v2) # 1*3 + 2*4 = 11\n",
"print(\"\\nРезультат умножения векторов (dot):\", result)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1759f664-5a9e-46fc-9e16-1c7f935f465e",
"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.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

409
pandas.ipynb Normal file
View File

@ -0,0 +1,409 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "3013204a-5530-4de5-9362-c91dcf217fe8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Техническая информация:\n",
"<class 'pandas.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 str \n",
" 1 Возраст 4 non-null int64\n",
" 2 Баллы 4 non-null int64\n",
"dtypes: int64(2), str(1)\n",
"memory usage: 228.0 bytes\n",
"None\n"
]
}
],
"source": [
"import pandas as pd\n",
"\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.info())\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b6287eb3-dcbe-4015-b86d-a4a8f42cbd03",
"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",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Анна</td>\n",
" <td>21</td>\n",
" <td>89</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Борис</td>\n",
" <td>22</td>\n",
" <td>76</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Виктор</td>\n",
" <td>23</td>\n",
" <td>95</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Галина</td>\n",
" <td>24</td>\n",
" <td>82</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Имя Возраст Баллы\n",
"0 Анна 21 89\n",
"1 Борис 22 76\n",
"2 Виктор 23 95\n",
"3 Галина 24 82"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d082ec60-d76b-4c2d-9471-ef6c9a11c6a7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1fd75bbf-d98d-4ef2-8541-2e6644ef26c2",
"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": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[\"Новый столбец\"] = df[\"Баллы\"] * 1.1\n",
"df # Выводим результат, чтобы проверить\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5768c86e-9f44-466f-a23d-41465cfa6807",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e7738859-8f4f-44dc-9afc-a0dcf195b7d2",
"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",
" </tr>\n",
" <tr>\n",
" <th>Имя</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Анна</th>\n",
" <td>89.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Борис</th>\n",
" <td>76.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Виктор</th>\n",
" <td>95.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Галина</th>\n",
" <td>82.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Баллы\n",
"Имя \n",
"Анна 89.0\n",
"Борис 76.0\n",
"Виктор 95.0\n",
"Галина 82.0"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Посчитаем средний балл (в данном случае он будет равен самому баллу)\n",
"grouped = df.groupby(\"Имя\").agg({\"Баллы\": \"mean\"})\n",
"grouped\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b20b87a-4a84-4fc7-8ff8-73853ece191c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"id": "155692d0-03dc-4802-b976-f422eb01b8c8",
"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>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",
"1 Борис 22 76 83.6\n",
"2 Виктор 23 95 104.5\n",
"3 Галина 24 82 90.2"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"filtered_df = df[df[\"Возраст\"] > 21]\n",
"filtered_df\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c4a5a6b8-fa2e-448e-8584-577f9134c876",
"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.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

115
seaborn.ipynb Normal file

File diff suppressed because one or more lines are too long

131
tqdm.ipynb Normal file
View File

@ -0,0 +1,131 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "bd70558d-d516-46a7-956d-d85685f46b96",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Простой процесс:\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Базовая загрузка: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:01<00:00, 93.30it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Обработка строк таблицы:\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Анализ данных: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:01<00:00, 3.32it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Стилизованная загрузка:\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Сохранение отчета: 100%|████████████████████| 100/100 [00:02<00:00, 48.43it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Все процессы завершены успешно!\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"from tqdm import tqdm\n",
"import time\n",
"import pandas as pd\n",
"\n",
"# 0. Создаем данные (чтобы не было ошибки \"df is not defined\")\n",
"data = {\n",
" \"Имя\": [\"Анна\", \"Борис\", \"Виктор\", \"Галина\", \"Дмитрий\", \"Елена\"],\n",
" \"Возраст\": [21, 22, 23, 24, 25, 26],\n",
" \"Баллы\": [89, 76, 95, 82, 90, 88]\n",
"}\n",
"df = pd.DataFrame(data)\n",
"\n",
"# 1. Базовый прогресс-бар\n",
"print(\"Простой процесс:\")\n",
"for i in tqdm(range(100), desc='Базовая загрузка'):\n",
" time.sleep(0.01)\n",
"\n",
"# 2. Использование tqdm для обработки данных таблицы\n",
"print(\"\\nОбработка строк таблицы:\")\n",
"# Здесь добавили .shape[0], чтобы tqdm знал общее количество строк\n",
"for index, row in tqdm(df.iterrows(), total=df.shape[0], desc='Анализ данных'):\n",
" time.sleep(0.3) # Симулируем обработку каждой строки\n",
"\n",
"# 3. Кастомная стилизация\n",
"print(\"\\nСтилизованная загрузка:\")\n",
"for i in tqdm(range(100), desc='Сохранение отчета', bar_format='{l_bar}{bar:20}{r_bar}'):\n",
" time.sleep(0.02)\n",
"\n",
"print(\"\\nВсе процессы завершены успешно!\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1beae766-f7ad-4e74-b6fa-a44ca8672667",
"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.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}