{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "3013204a-5530-4de5-9362-c91dcf217fe8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Техническая информация:\n", "\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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ИмяВозрастБаллы
0Анна2189
1Борис2276
2Виктор2395
3Галина2482
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ИмяВозрастБаллыНовый столбец
0Анна218997.9
1Борис227683.6
2Виктор2395104.5
3Галина248290.2
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Баллы
Имя
Анна89.0
Борис76.0
Виктор95.0
Галина82.0
\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ИмяВозрастБаллыНовый столбец
1Борис227683.6
2Виктор2395104.5
3Галина248290.2
\n", "
" ], "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 }