AIM-PIbd-32-Bulatova-K-R/lab_1/lab_1.ipynb

180 lines
113 KiB
Plaintext
Raw Normal View History

2024-09-28 09:06:50 +04:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Начало лабораторной работы\n",
"\n",
"Выгрузка данных из csv файла в датафрейм"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Index(['age', 'sex', 'bmi', 'children', 'smoker', 'region', 'charges'], dtype='object')\n"
]
}
],
"source": [
"import pandas as pd\n",
"df = pd.read_csv(\"..//static//csv//Medical_insurance.csv\")\n",
"print(df.columns)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAGFCAYAAAASI+9IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAnM0lEQVR4nO3deXhU5cH+8XuWJEBWdgQCyhIQUBYVqaJCRdFXXHFFccWqxdYq1L71fUvVlqL259rW5RWJUmoBW6pYUKsoIm4oEBYBUSAJYV+SQJZZMjO/PwaPRPZkkufMOd/PdeUKk5kkN3h57nmec87zeGKxWEwAAEjymg4AALAPSgEAYKEUAAAWSgEAYKEUAAAWSgEAYKEUAAAWSgEAYKEUAAAWSgEAYKEUAAAWSgEAYKEUAAAWSgEAYKEUAAAWSgEAYKEUAAAWSgEAYKEUAAAWSgEAYKEUAAAWSgEAYKEUAAAWSgEAYKEUAAAWSsElbr75Znk8Ht15550HPDd27Fh5PB7dfPPNjR8MgK1QCi6Sm5ur6dOnq7q62vpaIBDQq6++qk6dOhlMBsAuKAUXGTBggHJzczVr1izra7NmzVKnTp3Uv39/SdLUqVPVsmVLBYP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KnRz/hcq3l1lOgpgXL/cHOXffJqap6eajuJalIJBi4t2a8wrX6q0Kmw6CmAbeW0zNO2209WGE9BGUAqGvLVii34xo0DBmqjpKIDtdG7ZTNNuO125LZq
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"import pandas as pd \n",
"df = pd.read_csv(\"..//static//csv//Medical_insurance.csv\")\n",
"\n",
"labels = 'Мужчины', 'Женщины'\n",
"sizes = [df[df[\"sex\"] == \"male\"].shape[0],df[df[\"sex\"] == \"female\"].shape[0]]\n",
"\n",
"print(len([df[df[\"sex\"] == \"male\"].count(),df[df[\"sex\"] == \"female\"].count()]))\n",
"\n",
"plt.pie(sizes, labels=labels)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Данная круговая диаграмма показывает соотношение мужчин и женщин. Из диаграмм мы видим, что мужчин больше."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA2QAAAIjCAYAAABswtioAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACcqklEQVR4nOzde1xT9f8H8NfZxoBAQOQmYgpkMlGxwJC8h4pKmuYlzdLK1ExTu+nXygvlN79aqVlef5VaaZmalpdMg8wSMgXMwGtImhAomBAojO2c3x+2Mw4bymw0hNfz8fDxcO/z2dn7vZ2d8d7nnDNBkiQJRERERERE9K9TOToBIiIiIiKihooNGRERERERkYOwISMiIiIiInIQNmREREREREQOwoaMiIiIiIjIQdiQEREREREROQgbMiIiIiIiIgdhQ0ZEREREROQgbMiIiIiIiIgchA0ZERER0Q0sXLgQYWFhEEXR0alQPXLs2DFoNBpkZGQ4OhVyIDZkRDeQlZWFCRMmIC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Vq0kMaMGWMR1+v1kp+fn9S2bVvp6tWrcnzHjh0SAGn27NlybMyYMVKLFi3k2xkZGZJKpZL69etn8Ry0aNFC6t27t+Tj4yNt3rxZjr/22mvSvffeK7Vo0UKKj4+X40uWLJEASB9//LEit5iYGMnd3V0qLi6WJEmSkpKSJADSlClTLGqxVrvp+aycm8m3334rAZA2bdpksexGPvjgAwmAtGjRohrlMWfOHKm6jwRTjpGRkZJer5f
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"\n",
"df = pd.read_csv(\"..//static//csv//Medical_insurance.csv\")\n",
"\n",
"df_first_30 = df.head(30)\n",
"\n",
"region_charges = df_first_30.groupby('region')['charges'].mean().reset_index()\n",
"\n",
"plt.figure(figsize=(10, 6))\n",
"plt.bar(region_charges['region'], region_charges['charges'], color=['blue', 'green', 'red', 'purple'], alpha=0.7)\n",
"plt.title('Средняя стоимость страховки по регионам (первые 30 строк)')\n",
"plt.xlabel('Регион')\n",
"plt.ylabel('Средняя стоимость страховки')\n",
"plt.grid(axis='y', linestyle='--', alpha=0.7)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Данная столбчатая диаграмма показывает распределение стоимости страховки (charges) по регионам (region) для первых 30 строк данных. Это поможет нам увидеть, как стоимость страховки распределяется по регионам в выбранной выборке."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA/8AAAIjCAYAAABViau2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAB+TUlEQVR4nO3dd3hUZfr/8c9kQopACIGEEOmgEFpAQIwoxQChiDRREJUmKAJSXGFxpanfxbLSpMm6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2pqql577TVVrFhRgYGBKleunF5++WVdvXrVpV/btm1Vrlw5BQUFKSIiQo888oh+/vlnt9xyMtcdOHBAzz//vCpXrqzg4GAVK1ZMnTp1ctkOnc6dO6fBgwerXLlyCgwMVKlSpfT000/r1KlT5naQ3Y9zWTnnlVOnTrmMv3nzZtlsNs2aNcts6969uwoVKpTt+5txPXCOHxERoWvXrrn0nTdvnhlPxtfPqHv37pnmUalSJbNPuXLl9PDDD+urr75SrVq1FBQUpKpVq+rTTz81+/z++++y2WwaP36822ts2LBBNptN8+bNc4k9q5+M701O5+Zvv/1WnTp1UpkyZRQYGKjSpUtr8ODBbqfFOcesVauWW6xjx46VzWa74fIAkL9w2D8An7F06VJVqFBB999/f46fs27dOs2fP18vvPCCAgMDNXXqVLVo0UI//vijWZgfP35c9913n/kBOjw8XF9++aV69eql5OTkTItRSZo2bZr5wWj48OG5yu2dd97RiBEj1L59ew0bNkyBgYH69ttv3U5hyGm/zOzYsUMPPvigChQooD59+qhcuXLat2+fli5dqv/7v/9Thw4dXD7oDh48WNHR0erTp4/ZFh0dLel68dmjRw/Vq1dPY8eO1fHjxzVx4kR9//332rZtm0JDQ7OMY+TIkbpy5UqmjwUFBWnOnDl6++23VaBAAUnSoUOHtHr1agUFBbn0vXz5sho3bqzffvtN/fv3V/ny5bVgwQJ1795d586dc/kiqFevXpo1a5ZatmypZ555Rqmpqfr222/1ww8/qG7duvrvf/9r9nW+n+PHj1fx4sUlSSVKlLjh+3sjaWlpevjhh7V69Wp17txZAwcO1Pnz57Vq1SolJiaqadOmLnF8+umnWrx4sUtbxYoVXcbs37+/QkNDNXr0aO3du1fTpk3TgQMHzOJMur6sChUqpCFDhqhQoUJas2aNRo4cqeTkZL399tuSri/X1157TS+99JIeffRRPfLII7p48aK6d++uKlWq6NVXXzVfc/To0RozZoyaNm2qvn37mq+7adMmff/99+Zyk6QqVaroH//4hwzD0L59+zRu3Di1atVKBw8ezPJ9euaZZ7R27VqtWrVKVatWzbLfuXPnNHbs2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ZjyZIlbjGn72cYhjF06FAjIiLCqFOnjtvrZEaS0a9fP7f21q1bu6yjS5YsMSQZr7/+uku/Rx991LDZbMZvv/2W7evkJO/t27cbkoxnnnnGpd/f/vY3Q5KxZs2aLMf/5JNP3Oa1nM51ma0LCQkJhiTjww8/NNtGjhxpSDI+/fRTt/6ZrasZt/P0nOvxyZMnXdo3bdpkSDJmzpzpMk7BggUzHccp43rgHL9Lly7Gww8/bLYfOHDA8PPzM7p06ZLp62eWw41eu2zZsoYkY9GiRWZbUlKSUbJkSaN27dpm23vvvWdIMnbv3m22paSkGMWLF3eZU73x3ixYsMCQZHzzzTdmW2bLeezYsYbNZnOZ/51jtmnTxujfv7/Z/u233xrBwcFGu3btbvieAMhfOOwfgE9ITk6W5L4X5kZiY2NVp04d8/cyZcqobdu2WrlypdLS0mQYhhYtWqQ2bdrIMAydOnX
"text/plain": [
"<Figure size 1200x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"\n",
"df = pd.read_csv(\"..//static//csv//Medical_insurance.csv\")\n",
"\n",
"age_groups = df.groupby('age')['charges'].mean().reset_index()\n",
"\n",
"plt.figure(figsize=(12, 6))\n",
"plt.bar(age_groups['age'], age_groups['charges'], color='green', alpha=0.7)\n",
"plt.title('Средняя стоимость страховки по возрастным группам')\n",
"plt.xlabel('Возраст')\n",
"plt.ylabel('Средняя стоимость страховки')\n",
"plt.grid(axis='y', linestyle='--', alpha=0.7)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Данная гистограмма показывает распределение стоимости страховки (charges) по возрастным группам. Это поможет нам увидеть, как стоимость страховки меняется в зависимости от возраста."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "aimenv",
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}