230 lines
230 KiB
Plaintext
230 lines
230 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Начало лабораторной\n",
|
|||
|
"\n",
|
|||
|
"Выгрузка данных из csv файла в датафрейм"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 27,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Index(['Date', 'Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume'], dtype='object')\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import pandas as pd\n",
|
|||
|
"df = pd.read_csv(\".//static//csv//StarbucksDataset.csv\")\n",
|
|||
|
"print(df.columns)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"#### Гистограмма числа продаж кофе за год за весь период времени\n",
|
|||
|
"Эта гистограмма показывает изменение объемов продаж Starbucks по годам, а также динамику средней цены закрытия акций компании за те же годы. Сравнение объемов продаж и средней цены закрытия может дать понимание рыночной динамики. Например, если объемы продаж растут, а средняя цена закрытия акций также увеличивается, это свидетельствует о положительном восприятии инвесторов."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 29,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABBMAAAIjCAYAAABRbFPKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6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bNmmn8+PGSzN/7DRs2aMiQIfeN484//wQjR45MdH7jxg01btxYhw4d0sCBAxUaGqrvvvtOffr00aVLl1J1n2rVqumll15K1FaqVClJ5iyQxx57TKtXr1bfvn1VrVo1LVu2TK+88opOnjypSZMmJTvm4MGDVatWLUnSV199pRUrViS6vm3bNm3cuFE9evRQcHCwjhw5ounTp6tx48bas2ePcuXKlai/u7u75syZo2HDhtnaZs2aJW9vb7v+XgMAMjkDAJBhXbp0yZBkdOjQ4Z79HnvsMUOSceXKFcMwDEOSIclYs2aNrc/169eN8uXLG4GBgcbNmzcTvX716tWGJOO7776753369u1rBAUFGefOnUvU3qNHD8Pf39+4fv16ovF69uxp5MuXz4iNjbX1LV26tPH444+n6n6zZs0yJBnbtm1L1H727FlDkjFq1Chb26hRowxJxmOPPZaob//+/Q1Jxs6dOw3DMIzw8HBDkvHss88m6vfyyy8bkozff/89UfuBAwcMScZHH31ka/vwww8NSUZERIStLSYmxrBarYleGxERYXh5eRljxoxJ8t769+9v+Pj4GOHh4YZhGIneT69evYy8efMa+/fvv8dPxxQfH280atTIkGQUKlTI6NmzpzFt2jTj6NGjSfomF3eChD+7O7Vq1cooUaJEorbixYsbkoylS5cm6Z/we7d9+3Zb29GjRw1vb2+jU6dOtrbevXsbxYsXT/L6hD/DBAcPHjTc3NyMTp06JfnZxsfHJ4qpbdu2hmEYxuTJkw2LxWK8++67ifoPGTLE8PPzM+Li4pLc914iIiIMScaHH36Y5FrFihWNRo0a2c7DwsIMScacOXNsbTdv3jTq1Klj+Pj42P5+puTO95GcJUuWGJKMsWPHJmrv2rWrYbFYjEOHDiVqX758uSHJWLhwoa1twIABxt3//Evuz37Tpk2GJOOrr76ytSX8fezZs6dRuXJlW3t0dLTh5+dn+3t9999XAEDWxDIHAMjArl69Kkny9fW9Z7+E61euXLG11apVS40aNbKd58yZU/3791dkZKT+/PPPFO937ty5ZNfZG4ah77//Xu3bt5dhGDp37pzt0apVK12+fDnJuO3bt5fFYtGPP/4oSVq/fr1OnDih//znP/d/8w66+1v0QYMGSTJnE9z5PHz48ET9Er4NvnOGhyTbN63e3t73vK+Xl5fc3Mz/rVqtVp0/f14+Pj4qW7Zssj/vKVOmqHbt2mrfvr0iIyNt7e+++67mzp2r77//XmXKlLn3m5W5PGLZsmUaO3asAgICNG/ePA0YMEDFixfXf/7zn1TXTLiz5sHly5d17tw5NWrUSP/++68uX76cqG9oaKhatWqV7Dh16tTRQw89ZDsvVqyYOnTooGXLlslqtaYqlgRLlixRfHy83n77bdvPNkFyyyEmTJigIUOGaPz48XrzzTcTXcuTJ4+io6OTfCvvTL/++qsCAwPVs2dPW1uOHDk0ePBgXbt2TWvXrn3g8d3d3TV48OBE7S+99JIMw9Bvv/2WqD21v7t3/tnfunVL58+fV6lSpZQnT55kf3effPJJ7du3z7ac4fvvv5e/v7+aNWvm0PsCAGROWSaZsG7dOrVv316FCxeWxWJJtC44tb799ltVq1ZNuXLlUvHixfXhhx86P1AAsENCkiAhqZCS5JIOCRX
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1200x600 with 2 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import pandas as pd\n",
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"\n",
|
|||
|
"# Чтение данных из CSV файла\n",
|
|||
|
"df = pd.read_csv(\".//static//csv//StarbucksDataset.csv\")\n",
|
|||
|
"\n",
|
|||
|
"# Преобразование столбца 'Date' в формат datetime\n",
|
|||
|
"df['Date'] = pd.to_datetime(df['Date'])\n",
|
|||
|
"\n",
|
|||
|
"# Выделение года из даты\n",
|
|||
|
"df['Year'] = df['Date'].dt.year\n",
|
|||
|
"\n",
|
|||
|
"# Группировка по годам: получение суммы объема и средней цены закрытия\n",
|
|||
|
"yearly_data = df.groupby('Year').agg({'Volume': 'sum', 'Close': 'mean'}).reset_index()\n",
|
|||
|
"\n",
|
|||
|
"# Построение гистограммы\n",
|
|||
|
"plt.figure(figsize=(12, 6))\n",
|
|||
|
"\n",
|
|||
|
"# Гистограмма объемов продаж\n",
|
|||
|
"plt.bar(yearly_data['Year'], yearly_data['Volume'], alpha=0.6, color='b', label='Объем продаж')\n",
|
|||
|
"plt.ylabel('Объем продаж')\n",
|
|||
|
"plt.xlabel('Год')\n",
|
|||
|
"plt.title('Объем продаж Starbucks по годам')\n",
|
|||
|
"\n",
|
|||
|
"# Вторая ось для отображения средней цены закрытия\n",
|
|||
|
"ax2 = plt.gca().twinx()\n",
|
|||
|
"ax2.plot(yearly_data['Year'], yearly_data['Close'], color='r', marker='o', label='Цена закрытия')\n",
|
|||
|
"ax2.set_ylabel('Средняя цена закрытия')\n",
|
|||
|
"\n",
|
|||
|
"# Добавление легенды\n",
|
|||
|
"plt.legend(loc='upper left')\n",
|
|||
|
"ax2.legend(loc='upper right')\n",
|
|||
|
"\n",
|
|||
|
"# Отображение графика\n",
|
|||
|
"plt.show()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"#### Динамика объемов продаж Starbucks по годам\n",
|
|||
|
"\n",
|
|||
|
"Данный график отображает динамику объемов продаж, что позволяет сделать вывод о том, что на момент 2008 года объем продаж рос наиболее максимально. Сейчас же объем продаж почти на нуле."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 37,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKAAAAJICAYAAABWnpxpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADpXUlEQVR4nOzdd1zV9fcH8NedXPZeAiJbmeIA9y4tR2Xa0kob7uxbtjNHZctsqOXKNK3U1IZWpj+3mYJ7KwKCgAzZcOFy5+8PuDdJVEDgA9zX8/Hw8f12P/d+7ovLBe49933OW2QwGAwgIiIiIiIiIiJqJGKhAxARERERERERUevGAhQRERERERERETUqFqCIiIiIiIiIiKhRsQBFRERERERERESNigUoIiIiIiIiIiJqVCxAERERERERERFRo2IBioiIiIiIiIiIGhULUERERERERERE1KhYgCIiIiKiu2YwGISOQERERM0YC1BERNSivfHGGwgJCanx3xtvvCF0vFbDYDBg/fr1GD16NKKjo02PcVhYGA4ePCh0PGoku3fvxtNPP40uXbogIiIC99xzD+bNm4e8vLxq19u4cSM+/vjjBrnPRYsWISQkpEHOdSdPPvkknnzyySa5LyIiInMnFToAERHR3XJ1dcXixYurXTZt2jSB0rROH3zwAXbu3Innn38efn5+sLS0hFQqRZs2beDk5CR0PGoEv/zyC95880089thjGDduHCwtLZGYmIjly5djz5492Lx5M+zt7QEAS5YsQUxMjMCJiYiIqDljAYqIiFo0nU4HKysrdOzYsdrlcrlcmECtUH5+PtatW4fffvsNAQEBQsehJvLVV19h6NChmDNnjumybt26oUuXLnjggQewceNGPPfcc8IFJCIiohaFLXhERNSiabVaKBSKO17vjTfewIABA6pdtn79eoSEhGDRokUAgLi4OISEhCAuLq7a9f7bppOfn4+5c+eif//+CA8PR0xMDKZOnYr09PRqtwkJCcH48eOrnUun06Fnz54ICQnBzz//DAD4+eefERISUu32ly9fRlhYWLX7vTGrUqnEk08+idDQUFRUVAAALl68iGnTpqFbt24ICwtD79698f7770OlUt32sUlJScH06dPRs2dPdOzYEU8++SSOHTtmOn7s2DF4eXlBpVJh7NixiIyMRK9evfDhhx+ivLwcADBgwIBq7Y93cvToUYwdOxZRUVGIiYnB66+/jvz8fNNx42MSEhKC7Ozsarf9+OOPERISUu2xqaiowFdffYUhQ4YgIiIC9957L5YvXw69Xm+6jvF7YvzXqVMnPPPMM0hLS7tlTuNz4nYtnunp6QgJCcEff/yBSZMmISoqCv369cNXX31V7f51Oh1++OEHDB8+HJGRkejXrx8+/fRT0/fPqHfv3jXe343Pjzt9r8eMGYN+/frh4sWL1b4O43M7KSkJ99xzDx599NFbfu25ubk1znVq37493nzzTYSHhwOo/N5nZGTgl19+qZbzyJEjePbZZ9G1a1eEh4djwIABWLRokekxMT5uq1atwpAhQxAVFYXNmzeb7mfnzp0YPHgwIiIiMHr0aBw6dMh0rKafGWOWG1tv1Wo1vvjiCwwcOBCRkZEYNmwYfvnll1t+zQcOHEB4eDjefvttGAwG6PV6fP755xgwYIDpa1iwYAE0Gs0tz2FsIazpn/FnHrjzz11tz238nfDnn39i5MiRiI6ORs+ePTFr1iwUFRVVu/1jjz1WY64bf+elp6fjtddeQ69evRAWFobu3bvjtddeQ0FBQbXHOSQkBDNnzqx2/qKiIoSHh9f4e5SIiIgroIiIqEUrLy83tQHVRVFREb744os6385gMGDixIkoKirCK6+8AhcXF1y6dAlffPEFZs+ejZUrV5qua21tjSNHjqCkpAS2trYAgPj4+GqFlluZN28etFrtLY//+OOPyM3NxXfffQe5XI6cnByMGTMGHTt2xEcffQS5XI79+/dj1apVcHNzw4QJE2o8T2JiIh555BG0a9cOM2fOhEwmw5o1a/D000/j22+/RUxMDDIyMlBRUYEnn3wSI0aMwMSJE3H16lV89tlnSEhIwLfffovFixdDrVZj48aN2LRp022/tiNHjmD8+PHo1q0bvvjiCxQVFeHLL7/EU089hU2bNlUrKFpbW2PXrl144oknTI//tm3bIBb/+xmawWDApEmTcPLkSUybNg3t27dHXFwcvvjiC6SlpeG9994zXTc0NBSzZ8+GVqtFeno6FixYgNdeew3r1q27beZZs2YhLCzM9N81tXjOmTMHffv2xaJFi3Ds2DEsXrwYZWVlePXVV03n+O233/D888+jS5cuOH/+PL766itcuHAB33zzDUQiEYDKYtq7775rKuTt3bsXS5YsMd1Pbb7Xs2bNwvLlyzF//vxqz0mj+fPnIywsDJMnT77l19yvXz/88ccfqKiowH333YeuXbvC3d0dADBu3DjT9RYvXowJE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UMAAN27d8fAgQOxYsUKLFy48JaZ//s4bd++HW+99Raefvpp03kyMjIQFxdXrQB1+vRpTJw4EYMHD8a8efNMBZX4+HiEh4eb8sXExMDS0tJUUL6dG58v/12pVZufu9qeu6ioCEuWLMEjjzyCWbNmmS4PDg7GmDFjqv1MlZWVISgoyHT7/66+S0lJgYeHBz7++GP4+PgAqGy7PHXqFOLj46tdt3v37ti3bx9OnTplOt+2bdvu+PuNiIjMV6tvwfvhhx/q9Qn3iy++iH379mHevHn44YcfTJ8IqdXqhg9JRET1lpOTY3ojXFsJCQnYsGED3nnnnRqP6/V6aLVa078b25Dc3d2xZs0adO7cGenp6Th48CDWrl2L48eP3/Q3QiQSoX///ti1axeAynbBHTt2VHvz/V8VFRX4+OOPMXnyZLi6ut50XKvVYu3atVAqlRgxYoTp8l69euH777+HhYUFEhMTsWv
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1200x600 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"import pandas as pd\n",
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"import seaborn as sns\n",
|
|||
|
"\n",
|
|||
|
"# Загрузка данных\n",
|
|||
|
"df = pd.read_csv(\".//static//csv//StarbucksDataset.csv\")\n",
|
|||
|
"\n",
|
|||
|
"# Преобразование даты в формат datetime\n",
|
|||
|
"df['Date'] = pd.to_datetime(df['Date'])\n",
|
|||
|
"\n",
|
|||
|
"# Добавление колонки с годом\n",
|
|||
|
"df['Year'] = df['Date'].dt.year\n",
|
|||
|
"\n",
|
|||
|
"# Группировка данных по годам и суммирование объемов\n",
|
|||
|
"yearly_volume = df.groupby('Year')['Volume'].sum().reset_index()\n",
|
|||
|
"\n",
|
|||
|
"# Настройка стиля графика\n",
|
|||
|
"sns.set(style=\"whitegrid\")\n",
|
|||
|
"\n",
|
|||
|
"# Построение графика\n",
|
|||
|
"plt.figure(figsize=(12, 6))\n",
|
|||
|
"sns.lineplot(data=yearly_volume, x='Year', y='Volume', marker='o')\n",
|
|||
|
"plt.title('Динамика объемов продаж Starbucks по годам')\n",
|
|||
|
"plt.xlabel('Год')\n",
|
|||
|
"plt.ylabel('Объем продаж')\n",
|
|||
|
"plt.xticks(yearly_volume['Year'], rotation=45)\n",
|
|||
|
"plt.grid()\n",
|
|||
|
"\n",
|
|||
|
"# Показать график\n",
|
|||
|
"plt.tight_layout()\n",
|
|||
|
"plt.show()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"#### Круговая диаграмма среднего объема продаж за последние 10 лет.\n",
|
|||
|
"\n",
|
|||
|
"График показывает, что наибольший средний объем продаж был в 2018 году. "
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 47,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAxoAAAH5CAYAAAAGD0hXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3gU5fbA8e+W1E1PSKElAUKAACl0kaJSvKL+xKtXUVERpah4Bb1Yrh3FAiIodkABBSsWivTeCb0lQBoE0nvbPr8/YvYSQgmQZFPO53l4dGdn3jmzaXPmLUelKIqCEEIIIYQQQtQgtb0DEEIIIYQQQjQ+kmgIIYQQQgghapwkGkIIIYQQQogaJ4mGEEIIIYQQosZJoiGEEEIIIYSocZJoCCGEEEIIIWqcJBpCCCGEEEKIGieJhhBCCCGEEKLGSaIhhBACqd0qhBCipkmiIZqUw4cP85///IeBAw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RVWq9W2j8lkuuT5zrdnzx5Gjx5Njx496Ny5MzfffDOffPKJra2bbrqJ2267zXbN539dK47v16/fRb+fAYqLi9Hr9ZViqzBgwAAmTpxIq1atAGyxzZ49u1Kca9eu5YEHHiA6OprOnTtz66238v3339ver/jcfvjhB2666SZiYmIqDZ/78ccfbUMUH3nkEY4dO2Z778Lv7QoX/hwUFxczZcoU+vXrR1RUFP/85z/ZuHHjRa8Z4JdffqFDhw58+umnAOj1et544w369+9vu4YrDREzGAy88cYb9OnTh169evH8889TUFBge1+v1/Phhx8yZMgQOnfuTExMDKNGjeL48eOXbfdS3xfnDzOzWCx8//333HHHHXTt2pWBAwcyffp0DAZDpbY2bdrE/fffT1RUFDfeeCOvvfYahYWFtvdHjhxZre/DtWvXcvfdd9OlSxf69u3L22+/bfsdWOH++++/aDu7du0CIDU1tcrvM6g6hO5iw9wmTZpUqS2AEydOMHbsWGJiYoiJieGpp56q1tDW8ePH07x580s+LNq6dSuurq7ceOONtm0+Pj706NGDTZs2XbbtC3+vXexrB/Dzzz8zbNgwOnfuzMCBA/nkk0+wWCzApb/+1fk9KURDJj0aotFTFIWtW7dy88034+LictF9brvttirbFi1aRHBwMO+++y65ubl8+OGHpKSk8MMPP6BSqdizZw+jRo2id+/ezJw5k4KCAmbNmsXDDz/ML7/8grOzM1B+43Lfffdx9913A5CVlVUjw1ROnz7Nt99+e8X93nnnHcxm82X3OXXqFP/6178ICQnhlVdewcHBgQULFvDII48wb948evbsydmzZzEYDIwcOZI777yTsWPHcvr0aWbMmMGJEyeYN28es2fPxmg08vPPP/PLL79c9pzV/fwAdDod69at44EHHgDKv6Z//fUXanX1npXMnj2bZs2a2V7fd999VfaZOHEid911F+PGjWPdunW8+eabADzwwAMoisK4ceM4cOAATz/9NB06dGDXrl3MnDmTM2fO2ObAVNwQfv7557ahZBd+FnFxcTz66KPceuutfPTRRyiKwtKlS5k9ezZt2rRh2LBhzJw5kxkzZvDpp5/y1ltvVYl1ypQpDB06lIceeuii1+vj40NkZCRz584lMzOTwYMHExMTg4+PDw4ODowbN862748//sh9993HPffcw7333gvAxo0beeqpp3j44YeZMGECer2eRYsW8dZbb9G5c2ciIyMrfbavvPIKer2e6Oholi5dSnp6OrNnz+a5556zDVEZOXIkS5cupXnz5tX6mlksFh577DFbAtymTRt+++03nnrqKebPn0/37t0r7b9ixQpeffVVnnzySZ566imgfKjf1q1beeGFF/Dz82Pz5s188MEHeHl58c9//vOi5502bRq///47r776Kh4eHrz55pu88cYbfPTRRwBMnjyZ2NhYJk2aROvWrUlJSWHWrFk899xzLF++HJVKdclrOv8zhvK5MadOnbK9fu211/jjjz944okn6N69O8eOHePTTz/l+PHjzJkzB5VKxYYNGxg/fjy33HILM2fOJD8/nw8++ICzZ89WSqI6derE66+/bnt94ffh0qVLef7557njjjt49tlnOXv2LB999BGnTp3im2++sV2HwWBgwoQJthv0o0ePXvR78mrFxsayfPnyStuSkpK4//77adOmDe+//z5ms5nPP/+cESNG8Mcff+Dr63vJ9r777rvL3rQnJCTQsmVLNBpNpe2tW7dm6dKlV4x3wIABPPnkk7bXF37tvvzySz766CMeeughXnrpJY4fP84nn3xCWloaU6dO5ccffwT+9/m99tprREREXPG8QjR0kmiIRi8vLw+DwUDLli2v6ji1Ws0333yDu7s7UH7z9tRTT7Flyxb69+/Phx9+SGhoKF9++aXtj1fFhNtff/2VBx98EICysjJCQkKIiooCsD2Vvl5Tp04lLCyMo0ePXnKfVatWcfDgQUJDQy/b1uzZs3F0dGTBggW4ubkBMHDgQG6//XY++OADfvnlF0pLS0lLS+Ouu+7ijTfesB3r5+fHM888w+bNm21DErZs2XLF+Kv7+QH079+/UqKxf/9+CgoKqv2HumPHjlf8+g8ePNg2rK5fv35kZmby2WefMWLECDZv3sz27duZMWMGw4YNA6Bv3744OzvbkqOwsDDb0+Do6Gi8vb0v+lnExcVxww03MG3aNFui1LdvX9avX8+uXbsYNmwYkZGRjB07lieffJLnn3++0vE7duwgKSmJBQsW4OXldcnr+fjjj5k8eTK///47v//+OyqVirCwMAYPHswjjzxiG5Ne8X0ZGBho+/9Tp04xfPjwSsMMo6Oj6dWrF7t27aqUaDzwwAPceuutlc5tsVj49NNP6dq1K1D+dR00aBALFy7khRdeuOzXocLmzZs5ePAgn376KYMGDQKgd+/enDlzhp07d1ZKNDZs2MDkyZMZM2Y
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1000x600 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import pandas as pd\n",
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"\n",
|
|||
|
"# Загрузка датасета\n",
|
|||
|
"df = pd.read_csv(\".//static//csv//StarbucksDataset.csv\")\n",
|
|||
|
"\n",
|
|||
|
"# Убедитесь, что столбец 'Date' распознается как дата\n",
|
|||
|
"df['Date'] = pd.to_datetime(df['Date'])\n",
|
|||
|
"\n",
|
|||
|
"# Извлекаем год из даты\n",
|
|||
|
"df['Year'] = df['Date'].dt.year\n",
|
|||
|
"\n",
|
|||
|
"# Фильтрация для последних 10 лет\n",
|
|||
|
"current_year = df['Year'].max()\n",
|
|||
|
"last_10_years = df[df['Year'] >= (current_year - 10)]\n",
|
|||
|
"\n",
|
|||
|
"# Группировка данных по годам и расчет среднего объема\n",
|
|||
|
"average_volume_by_year = last_10_years.groupby('Year')['Volume'].mean()\n",
|
|||
|
"\n",
|
|||
|
"# Построение круговой диаграммы\n",
|
|||
|
"plt.figure(figsize=(10, 6))\n",
|
|||
|
"plt.pie(average_volume_by_year, labels=average_volume_by_year.index, autopct='%1.1f%%', startangle=140)\n",
|
|||
|
"plt.title('Средний объем продаж Starbucks за последние 10 лет')\n",
|
|||
|
"plt.axis('equal') # Чтобы круговая диаграмма была кругом\n",
|
|||
|
"plt.show()"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"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.6"
|
|||
|
}
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 2
|
|||
|
}
|