221 lines
162 KiB
Plaintext
221 lines
162 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Начало лабораторной работы\n",
|
|||
|
"\n",
|
|||
|
"Выгрузка данных из csv-файла в датафрейм:"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 158,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Index(['id', 'gender', 'age', 'hypertension', 'heart_disease', 'ever_married',\n",
|
|||
|
" 'work_type', 'Residence_type', 'avg_glucose_level', 'bmi',\n",
|
|||
|
" 'smoking_status', 'stroke'],\n",
|
|||
|
" dtype='object')\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import pandas as pd\n",
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"\n",
|
|||
|
"df = pd.read_csv(\"..//..//static//csv//healthcare-dataset-stroke-data.csv\")\n",
|
|||
|
"\n",
|
|||
|
"print(df.columns)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Диаграмма №1 (Круговая)\n",
|
|||
|
"\n",
|
|||
|
"Данная круговая диаграмма отображает распределение людей, перенесших инсульт, по их месту жительства. Это позволяет сделать вывод о том, что место, где живет человек, оказывает определенное влияние на вероятность инсульта. Так, у людей проживающих в сельской местности такая вероятность меньше, чем у жителей города."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 159,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"Text(0.5, 1.0, 'Распределение людей с инсультом по месту жительства')"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 159,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAnwAAAKSCAYAAABIowakAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABxDElEQVR4nO3dd3xV9eHG8efu7L1IAiQkJOwtKsiU4aBW66ijDtRq3diqVfuzrqq1WsVaW2utSq3VilarVgVxi4hb9g47Cdl73/P7A0kJCVkkOfee+3m/XrwgN3c8N/fk3ofvOd/vsRmGYQgAAACWZTc7AAAAAHoXhQ8AAMDiKHwAAAAWR+EDAACwOAofAACAxVH4AAAALI7CBwAAYHEUPgAAAIuj8AEAAFgchQ8IYPfee6+8Xq8kyev16r777jM5EQCgN1D4DvLMM8/IZrM1/wkKClJWVpauvvpq5efnmx0P6HGLFi3Sgw8+qN27d+v3v/+9Fi1aZHYkAEAvcJodwBfdddddSk9PV21trT755BP9+c9/1ptvvqk1a9YoJCTE7HhAj7nrrrt0wQUX6Je//KU8Ho/+8Y9/mB0JANALKHxtOPHEEzVhwgRJ0qWXXqrY2Fg99NBD+s9//qNzzjnH5HRAz/nxj3+sGTNmaMuWLRo8eLDi4+PNjgQA6AXs0u2EmTNnSpJycnIkScXFxbrhhhs0cuRIhYWFKSIiQieeeKK+++67Vretra3VHXfcoaysLAUFBalfv3760Y9+pK1bt0qStm/f3mI38qF/pk+f3nxfH3zwgWw2m/71r3/p1ltvVVJSkkJDQ3XKKado165drR575cqVOuGEExQZGamQkBBNmzZNy5cvb/M5Tp8+vc3Hv+OOO1pd9x//+IfGjx+v4OBgxcTE6Oyzz27z8dt7bgfzer1auHChhg8frqCgICUmJuryyy9XSUlJi+ulpaVp3rx5rR7n6quvbnWfbWV/4IEHWv1MJamurk633367MjMz5fF41L9/f910002qq6tr82fV3ed5aKa8vDxdcMEFio+Pl8fj0YgRI/TXv/61zcc49HCDA3/S0tJaXXfDhg0644wzFBMTo6CgIE2YMEGvvfZam/e3fft2JSQkaNKkSYqNjdWoUaNks9n0zDPPdPi8S0tLdf311ystLU0ej0epqam64IILVFhY2O7tOvvaHNjeX3rppVb3ERYWposuuqjTeSorKxUaGqrrrruu1X3t3r1bDoej1fGLh/udOPhnM336dI0YMaLD59vZ3/F9+/bpkksuUWJiooKCgjR69OhWu9kP3t5effXVFt+rra1VdHS0bDabHnzwwXZzHfj5Hu7PoT/fbdu26cwzz1RMTIxCQkJ0zDHH6L///W+7j3Hoz2DhwoWtvjdkyBDZbDZdffXVLS4vLS3VggUL1L9/f3k8HmVmZur+++9vPub0AK/Xq0ceeUQjR45UUFCQ4uPjdcIJJ+jLL79s8djt/fy7s30c7Ouvv1ZoaGir55CWltbi51hTU6OJEydq2LBhKi0tlfS/1/PQ37mrrrqqxetwuPeAw22bnXkfOKCntvUD/vGPf2jixIkKCQlRdHS0pk6dqqVLlzb/TNp7Dgfe0w59X3W5XEpLS9ONN96o+vr65sfqyudxoGOErxMOlLPY2FhJ+9/4Xn31VZ155plKT09Xfn6+/vKXv2jatGlat26dkpOTJUlNTU2aN2+e3n33XZ199tm67rrrVFFRoXfeeUdr1qxRRkZG82Occ845Oumkk1o87i233NJmnnvuuUc2m02//OUvtW/fPi1cuFCzZs3St99+q+DgYEnSe++9pxNPPFHjx4/X7bffLrvdrqefflozZ87Uxx9/rIkTJ7a639TU1OY3tcrKSl1xxRVtPvZtt92ms846S5deeqkKCgr06KOPaurUqfrmm28UFRXV6jaXXXaZpkyZIkn697//rVdeeaXF9y+//HI988wzmj9/vq699lrl5OToj3/8o7755hstX75cLperzZ9DV5SWlrb5hu31enXKKafok08+0WWXXaahQ4dq9erVevjhh7Vp06ZWH6jt6eh5Hqy+vl6zZs3Shg0bdMUVVyg7O1uvvvqqLrvsMhUVFenmm29u83YHDjeQpN///vetSvHatWs1efJkpaSk6Oabb1ZoaKhefPFFnXrqqXr55Zd12mmnHTbTs88+q9WrV3fquVZWVmrKlClav369Lr74Yo0bN06FhYV67bXXtHv3bsXFxXXqfqTDvzZd0VGeMWPG6LTTTtO//vUvPfTQQ3I4HM23ff7552UYhs4777xW9ztkyBD96le/kiQVFhbq+uuv73K2Z599tvnfH3/8sZ544gk9/PDDzT+jxMRESfvLwPTp07VlyxZdffXVSk9P1+LFi3XRRReptLS0VRkJCgrS008/rVNPPbX5sn//+9+qra3tUr5rr71WRx11VIvLLr300hZf5+fna9KkSaqurta1116r2NhYLVq0SKeccopeeumldrerQ/MuWLCg+bJPP/1UO3bsaHXd6upqTZs2TXv27NHll1+uAQMG6NNPP9Utt9yi3NzcFsXxkksu0TPPPKMTTzxRl156qRobG/Xxxx/rs88+04QJEzr18w8LC+vW9nHAuHHj9Nxzz+n000/XkCFDWhU/STIMQxdccIFycnK0cuXKNt8rD9iyZUur//xNnTq1xXO55557JKl5+5SkSZMmSere+0BPbOuSdOedd+qOO+7QpEmTdNddd8ntdmvlypV67733NGfOHC1cuFCVlZWSpPXr1+vee+/VrbfeqqFDh0ra/5+5gx14X62rq9OSJUv04IMPKigoSHfffbekzn8eQ5KBZk8//bQhyVi2bJlRUFBg7Nq1y3jhhReM2NhYIzg42Ni9e7dhGIZRW1trNDU1tbhtTk6O4fF4jLvuuqv5sqeeesqQZDz00EOtHsvr9TbfTpLxwAMPtLrO8OHDjWnTpjV//f777xuSjJSUFKO8vLz58hdffNGQZDzyyCPN9z148GBj7ty5zY9jGIZRXV1tpKenG7Nnz271WJMmTTJGjBjR/HVBQYEhybj99tubL9u+fbvhcDiMe+65p8VtV69ebTidzlaXb9682ZBkLFq0qPmy22+/3Th4s/v4448NScZzzz3X4rZvv/12q8sHDhxonHzyya2yX3XVVcahm/Kh2W+66SYjISHBGD9+fIuf6bPPPmvY7Xbj448/bnH7xx9/3JBkLF++vNXjHaozz/PQTI8++qghyXj88cebv9/Y2Ggcf/zxhsfjMQoLC1vc9oknnjAkGV9++WXzZSeffLIxcODAFtc7/vjjjZEjRxq1tbXNl3m9XmPSpEnG4MGDmy87sK3n5OQYhrF/mx4wYIBx4oknGpKMp59+ut3n/Otf/9qQZPz73/9u9b2Dt7m2dPa1ObC9L168uNV9hIaGGhdeeGGX8ixZssSQZLz11lstvj9q1KgWj3vA5MmTjRkzZjR/feB39eCfzbRp04zhw4e3+3wPdujP/WALFy40JBn/+Mc/mi+rr683jj32WCMsLKz5d/5AjnPOOcdwOp1GXl5e8/WPP/5449xzzz3se8rBuvLzXbBggSGpxe9JRUWFkZ6ebqSlpbV6PzyUJOOMM84wnE5ni234kksuac571VVXNV9+9913G6GhocamTZta3M/NN99sOBwOY+fOnYZhGMZ7771nSDKuvfbaVo/Z1nbY3s+/q9tHW373u98ZDofDePvttw3D2P+edeDneOuttxoej8f45JNPWtymre3qrLPOMkaMGGH079+/xetwsGnTph02V2ffBw7oqW198+bNht1uN0477bRW20Rbr8eBbfD9999v9b22MhiGYSQnJxsnnXRS89ed/TyGYbBLtw2zZs1SfHy8+vfvr7PPPlthYWF65ZVXlJKSIknyeDyy2/f/6JqamlRUVKSwsDBlZ2fr66+/br6fl19+WXFxcbrmmmtaPcahu/u64oILLlB4eHjz12eccYb69eunN998U5L07bffavPmzTr33HNVVFSkwsJCFRYWqqqqSscff7w++uijVrtFamtrFRQU1O7j/vvf/5bX69V
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 800x800 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"stroke_df = df[df['stroke'] == 1]\n",
|
|||
|
"\n",
|
|||
|
"residence_type_counts = stroke_df['Residence_type'].value_counts()\n",
|
|||
|
"\n",
|
|||
|
"plt.figure(figsize=(8, 8))\n",
|
|||
|
"plt.pie(residence_type_counts, labels=residence_type_counts.index, autopct='%1.1f%%', startangle=140, colors=plt.cm.Paired.colors)\n",
|
|||
|
"plt.title('Распределение людей с инсультом по месту жительства')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Диаграмма №2 (Столбчатая диаграмма)\n",
|
|||
|
"\n",
|
|||
|
"Данная столбчатая диаграмма построена на срезе данных, который содержит первых 100 пациентов с инсультом, и отображает их распределение по возрастным группам, включая разбивку по полу. Видно, что вероятность инсульта значительно увеличивается с возрастом, особенно начиная с 51 года, причём в группе 51-65 лет риск инсульта выше у мужчин, а в группе 66+ — у женщин. В более раннем возрасте инсульт одинаково опасен для представителей обоих полов."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 160,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"C:\\Users\\Ilya\\AppData\\Local\\Temp\\ipykernel_22732\\92582056.py:5: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n",
|
|||
|
" stroke_by_age_and_gender = stroke_patients.groupby(['age_group', 'gender']).size().unstack()\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.legend.Legend at 0x1dd9b8907a0>"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 160,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA28AAAI9CAYAAACt/kC0AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXR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GnHlvy5s2rjz76SNK9L+xTpkxRq1atdPr0afN6/9Zbb2nMmDFq2rSpBgwYoMOHD2v69Onavn27xbocFxenp556SgULFtTVq1f12WefqWXLljp48KDFDu/IkSN64okn9Nxzz6lnz56aPXu2Hn/8cS1fvlzNmjWTlH7bo6ZNm1qsH4l/q/e33b/Nygyurq76+uuvLdbV2bNny93dXTExMamez/Tp0y12yC4ulr//Xbt2Ta1atVKXLl3UrVs3ff/99xowYIBy5cqlPn36yNvbW4899pi+++47ffjhh3J1dTVP++2338owDHXv3t1inond7xMlt021Vd/x48f15ptvWoyzcuVK/fvvv+rdu7eCgoL0999/a+bMmfr777+1ZcsWqy9qN2/e1M8//6zHHnvM3GbPe7dv3z7Vq1dPOXPmVP/+/VWkSBEdO3ZMy5YtS9UFHlKzn1q4cKFu3bqlAQMGKE+ePNq2bZs++eQTnTlzRgsXLjTPKzo6Wo899piKFCmi27dva86cOerUqZM2b96sGjVqmAPsiBEjVKJECY0ZM0YxMTH69NNPVadOHW3fvl0lS5ZMttYPPvgg2fPaS5curZEjR8owDB07dkw
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1000x600 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"df['age_group'] = pd.cut(df['age'], bins=[0, 18, 35, 50, 65, 100], labels=['0-18', '19-35', '36-50', '51-65', '66+'])\n",
|
|||
|
"\n",
|
|||
|
"stroke_patients = df[df['stroke'] == 1].head(100)\n",
|
|||
|
"\n",
|
|||
|
"stroke_by_age_and_gender = stroke_patients.groupby(['age_group', 'gender']).size().unstack()\n",
|
|||
|
"\n",
|
|||
|
"plot = stroke_by_age_and_gender.plot(kind='bar', stacked=False, figsize=(10, 6), color=[\"pink\", \"blue\"])\n",
|
|||
|
"plot.set_title('Распределение инсультов по возрастным группам с разбивкой по полу (первые 100 пациентов)')\n",
|
|||
|
"plot.set_xlabel('Возрастная группа')\n",
|
|||
|
"plot.set_ylabel('Количество человек')\n",
|
|||
|
"plt.legend([\"Female\", \"Male\"])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Диаграмма №3 (Линейный график)\n",
|
|||
|
"\n",
|
|||
|
"Данная диаграмма отображает средний уровень глюкозы в различных возрастных группах для людей, у которых был инсульт и у которых его не было. Из нее можно сделать вывод о том, что уровень глюкозы у людей с инсультом отличается от уровня здоровых людей (понижен в молодости, при этом в более зрелом возрасте повышен)."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 161,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.legend.Legend at 0x1dd9a124ad0>"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 161,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA+0AAALgCAYAAADhrpZ5AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADmxUlEQVR4nOzdeZyNdf/H8deZ3ewGs9j3ZRAiGkup7EIiKVmLutujvV+hu10LWpQWEhWSUHdC1hghIcae3ZgxhlnNds71++OYwzEzZg4zc2Z5Px+PeXCu6zrXeZ8zZ66Zz/luJsMwDERERERERESkxHFxdgARERERERERyZ2KdhEREREREZESSkW7iIiIiIiISAmlol1ERERERESkhFLRLiIiIiIiIlJCqWgXERERERERKaFUtIuIiIiIiIiUUCraRUREREREREooFe0iIiIiIkUsKyuL2NhYjh496uwoIlLKqGgXEcn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ia3P5+z4v2c89t6/c1K5dO9djL33tsrKyeO2112jYsCGenp52x10p96XyynSln8+kpCQeffRRqlWrhqenJw0aNOCtt97CYrFc0/MuyHXo0vdQYGAgERERVK9end69e2MymZgwYUK+zzktLY0JEybQsGFDvLy8CAsL48477+TgwYNXvJ+j16l33303xzmaNWuW4z1zpTyOXLeyXX6tyf669LXJ6/px+fPN63t3+XNOSUlh3Lhx1KhRA09PTxo1asS7776bY3x49n0nT56c4/EaN25s+711JZf+HrhUQX4PgLVrfJ06dViwYAH16tXDw8ODmjVr8uyzz3L+/PkcxxfkejxhwgTCw8Px9fXF39+fG2+8kZ9++umKObLvZzKZiIuLs9u+ZcuWXJ/jnj17GDhwIEFBQXh5edGmTRsWL15sd0xe12KTycTx48dtx61cudL2vAIDA+nXrx+7d+/ON7OI2HNzdgARKVmWLFlC3bp1ad++fYHvs2bNGubOncvjjz+Op6cnn3zyCT169GDTpk22Ii4mJoYbb7zR9sdSlSpV+PXXX7n//vtJTEzMs8vptGnTbH/0vfDCC9f8/C6VlZXFSy+9VKBjDxw4wOeff57vcSaTifvuu4933nmH+Ph4goKCbPuWLFlCYmIi9913n919Xn/9dUwmE8899xyxsbFMnjyZLl26sG3bNtvcATNnzmTkyJHccMMNvPnmm8TExDBlyhTWr1/P33//TWBgoO18lStX5oMPPgDg+PHjTJkyhV69enHs2DHbcd988w3Dhw+ne/fuvP3226SmpjJt2jQ6duzI33//bfeHcnGpXr06b775pt22vOYP+OCDD6hcuTJgff2u5MCBA3Tu3Blvb2+eeeYZvL29+fzzz+nSpQvLly/npptuyvV+x44do0ePHjRu3Jh58+bh5mb9lRkTE0P79u1JTU3l8ccfp1KlSnz99df07duXH374gf79+wPWorNJkyYMGjQIb29vIiMjeeedd0hNTeXDDz906LVx1OOPP24bMztr1iyWL1+e57GdOnVizJgxAOzevZs33njDbv97773Hyy+/TP/+/Xnuuefw9PRk3bp1Dg+R6d+/P3feeSdAge4/YMAAli9fzrBhw2jbti2rVq3ihRde4PDh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orP+auvvjIA4/3338+x79LXMTeOXqcmTZqU4xyXXysLkqeg161sQ4YMMerUqWO37fLXJq/rR15ye92z/fTTTwZgvPbaa3bbBw4caJhMJuPAgQN2OQYOHGi4ubnZ/W66//77jXvvvdcAjEceeeSKWa7198Dw4cMNwBgxYoTd9vHjxxuAsWTJEsMwHLseXy42NtYAjHffffeKWbIf8/T
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1200x800 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"stroke_patients = df[df['stroke'] == 1].copy() \n",
|
|||
|
"no_stroke_patients = df[df['stroke'] == 0].copy() \n",
|
|||
|
"\n",
|
|||
|
"age_bins = range(0, 101, 10) \n",
|
|||
|
"\n",
|
|||
|
"stroke_patients['age_group'] = pd.cut(stroke_patients['age'], bins=age_bins)\n",
|
|||
|
"mean_glucose_stroke = stroke_patients.groupby('age_group', observed=False)['avg_glucose_level'].mean()\n",
|
|||
|
"\n",
|
|||
|
"no_stroke_patients['age_group'] = pd.cut(no_stroke_patients['age'], bins=age_bins)\n",
|
|||
|
"mean_glucose_no_stroke = no_stroke_patients.groupby('age_group', observed=False)['avg_glucose_level'].mean()\n",
|
|||
|
"\n",
|
|||
|
"plt.figure(figsize=(12, 8))\n",
|
|||
|
"plt.plot(mean_glucose_stroke.index.astype(str), mean_glucose_stroke, marker='o', label='С инсультом')\n",
|
|||
|
"plt.plot(mean_glucose_no_stroke.index.astype(str), mean_glucose_no_stroke, marker='o', label='Без инсульта')\n",
|
|||
|
"plt.xlabel('Возрастная группа')\n",
|
|||
|
"plt.ylabel('Средний уровень глюкозы')\n",
|
|||
|
"plt.title('Средний уровень глюкозы для людей с инсультом и без него')\n",
|
|||
|
"plt.xticks(rotation=45)\n",
|
|||
|
"plt.legend()\n",
|
|||
|
"\n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"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
|
|||
|
}
|