{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6ad35669",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np \n",
    "import glob\n",
    "import os "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9fcdc77a",
   "metadata": {},
   "outputs": [],
   "source": [
    "calendario = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\BASE DE DADOS LANÇAMENTO\\BOT\\CICLO 9\\CALENDARIO_CICLO\\Ciclo_Expandido_com_Datas.xlsx\")\n",
    "\n",
    "calendario['Date'] = pd.to_datetime(calendario['Date'])\n",
    "\n",
    "# Get today (normalized to midnight)\n",
    "today = pd.Timestamp(\"today\").normalize()\n",
    "\n",
    "calendario['NUM_CICLO'] = calendario['Ciclo'].str[-2:].astype(int)\n",
    "\n",
    "calendario['ANO_CICLO'] = calendario['Ciclo'].str[0:5]\n",
    "\n",
    "calendario = calendario[calendario['MARCA'] == \"EUDORA\"]\n",
    "\n",
    "calendario['CICLOMAIS2'] = calendario['ANO_CICLO'].astype(str) + (calendario['NUM_CICLO'].astype(int) + 3).astype(str).str.zfill(2)       #<<< MUDAR O \"4\" (CICLO ATUAL + 4 PARA ACHAR O CICLO DA SUGESTÃO) EX: C202505 -> C202509\n",
    "ciclo_mais2 = calendario[calendario['Date'].dt.normalize() == today]['CICLOMAIS2'].iloc[0]\n",
    "\n",
    "# Filter rows where date matches today\n",
    "filtered_calendario = calendario[calendario['Ciclo'] == ciclo_mais2][:1]\n",
    "\n",
    "filtered_calendario['dias_ate_inicio'] = filtered_calendario['INICIO CICLO'].iloc[0] - today\n",
    "\n",
    "filtered_calendario['dias_ate_inicio'] = filtered_calendario['dias_ate_inicio'].dt.days.astype(int)\n",
    "\n",
    "filtered_calendario['match'] = 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bbec229d",
   "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>Ciclo</th>\n",
       "      <th>INICIO CICLO</th>\n",
       "      <th>FIM CICLO</th>\n",
       "      <th>DURAÇÃO</th>\n",
       "      <th>MARCA</th>\n",
       "      <th>Date</th>\n",
       "      <th>NUM_CICLO</th>\n",
       "      <th>ANO_CICLO</th>\n",
       "      <th>CICLOMAIS2</th>\n",
       "      <th>dias_ate_inicio</th>\n",
       "      <th>match</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2430</th>\n",
       "      <td>C202515</td>\n",
       "      <td>2025-10-08</td>\n",
       "      <td>2025-10-28</td>\n",
       "      <td>21</td>\n",
       "      <td>EUDORA</td>\n",
       "      <td>2025-10-08</td>\n",
       "      <td>15</td>\n",
       "      <td>C2025</td>\n",
       "      <td>C202518</td>\n",
       "      <td>50</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        Ciclo INICIO CICLO  FIM CICLO  DURAÇÃO   MARCA       Date  NUM_CICLO  \\\n",
       "2430  C202515   2025-10-08 2025-10-28       21  EUDORA 2025-10-08         15   \n",
       "\n",
       "     ANO_CICLO CICLOMAIS2  dias_ate_inicio  match  \n",
       "2430     C2025    C202518               50      1  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filtered_calendario"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "61ffc777",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_similares = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\EUDORA\\C15\\SIMILARES\\PRODUTOS SIMILARES - EUD.xlsx\")\n",
    "\n",
    "df_similares = pd.merge(left=df_similares,right=calendario[['Ciclo','INICIO CICLO','FIM CICLO','DURAÇÃO']], how= 'left', left_on = 'CICLO SIMILAR',right_on = 'Ciclo' )\n",
    "\n",
    "df_similares = df_similares.drop(columns=['Ciclo'])\n",
    "\n",
    "df_similares = df_similares.rename(columns={'INICIO CICLO':'INICIO CICLO SIMILAR','FIM CICLO':'FIM CICLO SIMILAR','DURAÇÃO':'DURAÇÃO CICLO SIMILAR'})\n",
    "df_similares.drop_duplicates(inplace=True)\n",
    "\n",
    "df_similares['MATCH'] = 1\n",
    "\n",
    "df_similares = df_similares.drop(columns=['INICIO DO CICLO',\n",
    "       'FIM DO CICLO', 'DURAÇÃO CICLO','INICIO CICLO SIMILAR','FIM CICLO SIMILAR','DURAÇÃO CICLO SIMILAR'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "99ea95e6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['PRODUTO LANÇAMENTO', 'DESCRIÇÃO DO LANÇAMENTO', 'PRODUTO SIMILAR',\n",
       "       'DESCRIÇÃO SIMILAR', 'CICLO SIMILAR', 'FOCO', 'IAF', 'CATEGORIA',\n",
       "       'MARCA', '% CONSUMIDOR', 'MECANICA CONSUMIDOR', '% REVENDEDOR',\n",
       "       'MECANICA REVENDEDOR', 'TIPO DE PRODUTO', 'CAMPANHA', 'MATCH'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_similares.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fe922f62",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\EUDORA\\C15\\tabela de pedido\\Pedidos Semanais Especiais - GKD - 202515.xlsx\")\n",
    "\n",
    "df_tabela = df_tabela[df_tabela['Região'] == 'NNE'] \n",
    "\n",
    "df_tabela = df_tabela[(df_tabela['Canal'] != 'Ecomm') | (df_tabela['Canal'] != 'Ecomm | VD') | (df_tabela['Canal'] != 'Ecomm | Loja')] \n",
    "\n",
    "df_tabela['Canal'] = np.where((df_tabela['Canal'] == \"Loja\") | (df_tabela['Canal'] == \"Todos\") | (df_tabela['Canal'] == \"Loja | VD\"),\"TODOS\",\"VD\")\n",
    "\n",
    "#df_tabela = df_tabela[df_tabela['Tipo de promoção'].str.contains('Lançamentos', na=False)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a3a045d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_pdv = pd.read_excel(r\"C:\\Users\\joao.herculano\\Documents\\PDV_ATT.xlsx\")\n",
    "\n",
    "df_pdv_origi = pd.read_excel(r\"C:\\Users\\joao.herculano\\Documents\\PDV_ATT.xlsx\")\n",
    "\n",
    "df_pdv = df_pdv.rename(columns={'DESCRIÇÃO':'DESCRIÇÃO PDV'})\n",
    "\n",
    "df_pdv = df_pdv.drop(columns=['REGIÃO', 'ESTADO','CIDADE','GESTÃO','MARCA'])\n",
    "\n",
    "df_pdv = df_pdv[df_pdv['CANAL'].isin(['HIB','VD', 'CD'])]\n",
    "\n",
    "df_pdv = df_pdv[df_pdv['STATUS'] == 'ATIVO']\n",
    "\n",
    "df_pdv['PDV DESC'] = df_pdv['DESCRIÇÃO PDV']\n",
    "\n",
    "df_pdv['MATCH'] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "737ade5c",
   "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>PDV</th>\n",
       "      <th>CANAL</th>\n",
       "      <th>DESCRIÇÃO PDV</th>\n",
       "      <th>PDV DESC</th>\n",
       "      <th>UF</th>\n",
       "      <th>ANALISTA</th>\n",
       "      <th>SUPERVISOR</th>\n",
       "      <th>STATUS</th>\n",
       "      <th>MATCH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      PDV CANAL DESCRIÇÃO PDV  PDV DESC   UF ANALISTA  \\\n",
       "77  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "\n",
       "                    SUPERVISOR STATUS  MATCH  \n",
       "77  Arianne Sodré [Provisório]  ATIVO      1  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_pdv[df_pdv['PDV']==24255]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "849d5297",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['PDV', 'CANAL', 'DESCRIÇÃO PDV', 'PDV DESC', 'UF', 'ANALISTA',\n",
       "       'SUPERVISOR', 'STATUS', 'MATCH'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_pdv.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "df04a501",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_similares = pd.merge(left=df_similares,right=df_pdv,right_on=['MATCH'],left_on=['MATCH'],how='inner')\n",
    "\n",
    "df_similares = df_similares.drop_duplicates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a7d04631",
   "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>PRODUTO LANÇAMENTO</th>\n",
       "      <th>DESCRIÇÃO DO LANÇAMENTO</th>\n",
       "      <th>PRODUTO SIMILAR</th>\n",
       "      <th>DESCRIÇÃO SIMILAR</th>\n",
       "      <th>CICLO SIMILAR</th>\n",
       "      <th>FOCO</th>\n",
       "      <th>IAF</th>\n",
       "      <th>CATEGORIA</th>\n",
       "      <th>MARCA</th>\n",
       "      <th>% CONSUMIDOR</th>\n",
       "      <th>...</th>\n",
       "      <th>CAMPANHA</th>\n",
       "      <th>MATCH</th>\n",
       "      <th>PDV</th>\n",
       "      <th>CANAL</th>\n",
       "      <th>DESCRIÇÃO PDV</th>\n",
       "      <th>PDV DESC</th>\n",
       "      <th>UF</th>\n",
       "      <th>ANALISTA</th>\n",
       "      <th>SUPERVISOR</th>\n",
       "      <th>STATUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>86312</td>\n",
       "      <td>DIVA CREM HID MAOS 50g</td>\n",
       "      <td>93924</td>\n",
       "      <td>DIVA CREM HID MAOS ESPLENDIDA 50g]</td>\n",
       "      <td>C202202</td>\n",
       "      <td>Não</td>\n",
       "      <td>Não</td>\n",
       "      <td>CUIDADOS COM A PELE</td>\n",
       "      <td>DIVA</td>\n",
       "      <td>0,00</td>\n",
       "      <td>...</td>\n",
       "      <td>Lançamentos</td>\n",
       "      <td>1</td>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>84959</td>\n",
       "      <td>EUD MAKE BAS LIQ CONTR SK/PERF 100F 30ml</td>\n",
       "      <td>50634</td>\n",
       "      <td>GLAM BASE LIQ SK/CONTR COR 00 30ml</td>\n",
       "      <td>C202305</td>\n",
       "      <td>Não</td>\n",
       "      <td>Não</td>\n",
       "      <td>MAQUIAGEM</td>\n",
       "      <td>EUDORA MAKE</td>\n",
       "      <td>0,00</td>\n",
       "      <td>...</td>\n",
       "      <td>Lançamentos</td>\n",
       "      <td>1</td>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>84960</td>\n",
       "      <td>EUD MAKE BAS LIQ CONTR SK/PERF 120N 30ml</td>\n",
       "      <td>50630</td>\n",
       "      <td>GLAM BASE LIQ SK/CONTR COR 05 30ml</td>\n",
       "      <td>C202305</td>\n",
       "      <td>Não</td>\n",
       "      <td>Não</td>\n",
       "      <td>MAQUIAGEM</td>\n",
       "      <td>EUDORA MAKE</td>\n",
       "      <td>0,00</td>\n",
       "      <td>...</td>\n",
       "      <td>Lançamentos</td>\n",
       "      <td>1</td>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>84962</td>\n",
       "      <td>EUD MAKE BAS LIQ CONTR SK/PERF 140Q 30ml</td>\n",
       "      <td>50629</td>\n",
       "      <td>GLAM BASE LIQ SK/CONTR COR 10 30ml</td>\n",
       "      <td>C202305</td>\n",
       "      <td>Não</td>\n",
       "      <td>Não</td>\n",
       "      <td>MAQUIAGEM</td>\n",
       "      <td>EUDORA MAKE</td>\n",
       "      <td>0,00</td>\n",
       "      <td>...</td>\n",
       "      <td>Lançamentos</td>\n",
       "      <td>1</td>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>150</th>\n",
       "      <td>84963</td>\n",
       "      <td>EUD MAKE BAS LIQ CONTR SK/PERF 170Q 30ml</td>\n",
       "      <td>50628</td>\n",
       "      <td>GLAM BASE LIQ SK/CONTR COR 15 30ml</td>\n",
       "      <td>C202305</td>\n",
       "      <td>Não</td>\n",
       "      <td>Não</td>\n",
       "      <td>MAQUIAGEM</td>\n",
       "      <td>EUDORA MAKE</td>\n",
       "      <td>0,00</td>\n",
       "      <td>...</td>\n",
       "      <td>Lançamentos</td>\n",
       "      <td>1</td>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2475</th>\n",
       "      <td>19047</td>\n",
       "      <td>19047 COMBO TRIO BÁSICO 30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2506</th>\n",
       "      <td>52168</td>\n",
       "      <td>NEO DERMO GEL LIMP FAC PURIFIC 150g</td>\n",
       "      <td>52168</td>\n",
       "      <td>NEO DERMO GEL LIMP FAC PURIFIC 150g</td>\n",
       "      <td>C202311</td>\n",
       "      <td>Não</td>\n",
       "      <td>Não</td>\n",
       "      <td>CUIDADOS FACIAIS</td>\n",
       "      <td>NEO DERMO</td>\n",
       "      <td>19,34 | 25,14 | 7,00</td>\n",
       "      <td>...</td>\n",
       "      <td>Promoções</td>\n",
       "      <td>1</td>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2537</th>\n",
       "      <td>52038</td>\n",
       "      <td>NEO DERMO CR ANTIS FAC 30 PRO AGE 50g</td>\n",
       "      <td>52038</td>\n",
       "      <td>NEO DERMO CR ANTIS FAC 30 PRO AGE 50g</td>\n",
       "      <td>C202308</td>\n",
       "      <td>Não</td>\n",
       "      <td>Não</td>\n",
       "      <td>CUIDADOS FACIAIS</td>\n",
       "      <td>NEO DERMO</td>\n",
       "      <td>20,09 | 25,14 | 7,00</td>\n",
       "      <td>...</td>\n",
       "      <td>Promoções</td>\n",
       "      <td>1</td>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2568</th>\n",
       "      <td>19048</td>\n",
       "      <td>COMBO TRIO BASICO 45</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2599</th>\n",
       "      <td>52033</td>\n",
       "      <td>NEO DERMO CR ANTIS FAC 45 PRO AGE 50g</td>\n",
       "      <td>52038</td>\n",
       "      <td>NEO DERMO CR ANTIS FAC 30 PRO AGE 50g</td>\n",
       "      <td>C202308</td>\n",
       "      <td>Não</td>\n",
       "      <td>Não</td>\n",
       "      <td>CUIDADOS FACIAIS</td>\n",
       "      <td>NEO DERMO</td>\n",
       "      <td>20,09 | 25,14 | 7,00</td>\n",
       "      <td>...</td>\n",
       "      <td>Promoções</td>\n",
       "      <td>1</td>\n",
       "      <td>24255</td>\n",
       "      <td>VD</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>VD Irecê</td>\n",
       "      <td>BA3</td>\n",
       "      <td>LAIS</td>\n",
       "      <td>Arianne Sodré [Provisório]</td>\n",
       "      <td>ATIVO</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>84 rows × 24 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      PRODUTO LANÇAMENTO                   DESCRIÇÃO DO LANÇAMENTO  \\\n",
       "26                 86312                    DIVA CREM HID MAOS 50g   \n",
       "57                 84959  EUD MAKE BAS LIQ CONTR SK/PERF 100F 30ml   \n",
       "88                 84960  EUD MAKE BAS LIQ CONTR SK/PERF 120N 30ml   \n",
       "119                84962  EUD MAKE BAS LIQ CONTR SK/PERF 140Q 30ml   \n",
       "150                84963  EUD MAKE BAS LIQ CONTR SK/PERF 170Q 30ml   \n",
       "...                  ...                                       ...   \n",
       "2475               19047                19047 COMBO TRIO BÁSICO 30   \n",
       "2506               52168       NEO DERMO GEL LIMP FAC PURIFIC 150g   \n",
       "2537               52038     NEO DERMO CR ANTIS FAC 30 PRO AGE 50g   \n",
       "2568               19048                      COMBO TRIO BASICO 45   \n",
       "2599               52033     NEO DERMO CR ANTIS FAC 45 PRO AGE 50g   \n",
       "\n",
       "      PRODUTO SIMILAR                      DESCRIÇÃO SIMILAR CICLO SIMILAR  \\\n",
       "26              93924     DIVA CREM HID MAOS ESPLENDIDA 50g]       C202202   \n",
       "57              50634     GLAM BASE LIQ SK/CONTR COR 00 30ml       C202305   \n",
       "88              50630     GLAM BASE LIQ SK/CONTR COR 05 30ml       C202305   \n",
       "119             50629     GLAM BASE LIQ SK/CONTR COR 10 30ml       C202305   \n",
       "150             50628     GLAM BASE LIQ SK/CONTR COR 15 30ml       C202305   \n",
       "...               ...                                    ...           ...   \n",
       "2475                0                                      0             0   \n",
       "2506            52168    NEO DERMO GEL LIMP FAC PURIFIC 150g       C202311   \n",
       "2537            52038  NEO DERMO CR ANTIS FAC 30 PRO AGE 50g       C202308   \n",
       "2568                0                                      0             0   \n",
       "2599            52038  NEO DERMO CR ANTIS FAC 30 PRO AGE 50g       C202308   \n",
       "\n",
       "     FOCO  IAF            CATEGORIA        MARCA          % CONSUMIDOR  ...  \\\n",
       "26    Não  Não  CUIDADOS COM A PELE         DIVA                  0,00  ...   \n",
       "57    Não  Não            MAQUIAGEM  EUDORA MAKE                  0,00  ...   \n",
       "88    Não  Não            MAQUIAGEM  EUDORA MAKE                  0,00  ...   \n",
       "119   Não  Não            MAQUIAGEM  EUDORA MAKE                  0,00  ...   \n",
       "150   Não  Não            MAQUIAGEM  EUDORA MAKE                  0,00  ...   \n",
       "...   ...  ...                  ...          ...                   ...  ...   \n",
       "2475    0    0                    0            0                     0  ...   \n",
       "2506  Não  Não     CUIDADOS FACIAIS    NEO DERMO  19,34 | 25,14 | 7,00  ...   \n",
       "2537  Não  Não     CUIDADOS FACIAIS    NEO DERMO  20,09 | 25,14 | 7,00  ...   \n",
       "2568    0    0                    0            0                     0  ...   \n",
       "2599  Não  Não     CUIDADOS FACIAIS    NEO DERMO  20,09 | 25,14 | 7,00  ...   \n",
       "\n",
       "         CAMPANHA MATCH    PDV CANAL DESCRIÇÃO PDV  PDV DESC   UF ANALISTA  \\\n",
       "26    Lançamentos     1  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "57    Lançamentos     1  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "88    Lançamentos     1  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "119   Lançamentos     1  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "150   Lançamentos     1  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "...           ...   ...    ...   ...           ...       ...  ...      ...   \n",
       "2475            0     1  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "2506    Promoções     1  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "2537    Promoções     1  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "2568            0     1  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "2599    Promoções     1  24255    VD      VD Irecê  VD Irecê  BA3     LAIS   \n",
       "\n",
       "                      SUPERVISOR STATUS  \n",
       "26    Arianne Sodré [Provisório]  ATIVO  \n",
       "57    Arianne Sodré [Provisório]  ATIVO  \n",
       "88    Arianne Sodré [Provisório]  ATIVO  \n",
       "119   Arianne Sodré [Provisório]  ATIVO  \n",
       "150   Arianne Sodré [Provisório]  ATIVO  \n",
       "...                          ...    ...  \n",
       "2475  Arianne Sodré [Provisório]  ATIVO  \n",
       "2506  Arianne Sodré [Provisório]  ATIVO  \n",
       "2537  Arianne Sodré [Provisório]  ATIVO  \n",
       "2568  Arianne Sodré [Provisório]  ATIVO  \n",
       "2599  Arianne Sodré [Provisório]  ATIVO  \n",
       "\n",
       "[84 rows x 24 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_similares[df_similares['PDV'] == 24255]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0da911af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(84064, 46)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Caminho onde estão as subpastas com os arquivos CSV\n",
    "\n",
    "# Set the path to the folder containing CSV files\n",
    "folder_path = r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\BOT\\BOT - C15\\arquivos para geração da sugestão\\DRAFT\"  # arquivo dos drafts\n",
    "\n",
    "# Pattern to match all CSV files\n",
    "csv_files = glob.glob(os.path.join(folder_path, '*.csv'))\n",
    "\n",
    "# Read and concat all CSVs\n",
    "df_draft = pd.concat([pd.read_csv(file) for file in csv_files], ignore_index=True)\n",
    "\n",
    "df_draft['match'] = 1 \n",
    "\n",
    "df_draft.shape\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0c8c7493",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_draft = df_draft.drop(columns=['Categoria'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "91298cde",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Histórico de Vendas do Ciclo 202412',\n",
       "       'Histórico de Vendas do Ciclo 202413',\n",
       "       'Histórico de Vendas do Ciclo 202414',\n",
       "       'Histórico de Vendas do Ciclo 202415',\n",
       "       'Histórico de Vendas do Ciclo 202416',\n",
       "       'Histórico de Vendas do Ciclo 202417',\n",
       "       'Histórico de Vendas do Ciclo 202501',\n",
       "       'Histórico de Vendas do Ciclo 202502',\n",
       "       'Histórico de Vendas do Ciclo 202503',\n",
       "       'Histórico de Vendas do Ciclo 202504',\n",
       "       'Histórico de Vendas do Ciclo 202505',\n",
       "       'Histórico de Vendas do Ciclo 202506',\n",
       "       'Histórico de Vendas do Ciclo 202507',\n",
       "       'Histórico de Vendas do Ciclo 202508',\n",
       "       'Histórico de Vendas do Ciclo 202509',\n",
       "       'Histórico de Vendas do Ciclo 202510',\n",
       "       'Histórico de Vendas do Ciclo 202511',\n",
       "       'Histórico de Vendas do Ciclo Atual'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_draft.columns[7:25]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "34e179cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\joao.herculano\\AppData\\Local\\Temp\\ipykernel_33884\\1463083786.py:24: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.\n",
      "  crescimento_por_pdv = df_draft.groupby('PDV').apply(calcular_crescimento)\n"
     ]
    }
   ],
   "source": [
    "# Define as colunas mensais\n",
    "colunas_mensais = df_draft.columns[7:25]\n",
    "\n",
    "# Agrupa por PDV e calcula crescimento médio por PDV\n",
    "def calcular_crescimento(grupo):\n",
    "    soma_mensal = grupo[colunas_mensais].sum()             # soma por mês\n",
    "    variacao_mensal = soma_mensal.pct_change().dropna()    # variação percentual mês a mês\n",
    "    variacao_mensal = variacao_mensal[np.isfinite(variacao_mensal)]\n",
    "\n",
    "    if len(variacao_mensal) == 0:\n",
    "        return pd.Series({'CRESCIMENTO': np.nan})\n",
    "\n",
    "    media = variacao_mensal.mean()\n",
    "    desvio = variacao_mensal.std()\n",
    "\n",
    "    limite_sup = media + 2 * desvio\n",
    "    limite_inf = media - 2 * desvio\n",
    "\n",
    "    variacoes_filtradas = variacao_mensal[variacao_mensal.between(limite_inf, limite_sup)]\n",
    "    crescimento = round(variacoes_filtradas.mean(), 4)\n",
    "    return pd.Series({'CRESCIMENTO': crescimento})\n",
    "\n",
    "# Aplica a função por PDV\n",
    "crescimento_por_pdv = df_draft.groupby('PDV').apply(calcular_crescimento)\n",
    "\n",
    "# Merge do resultado de volta no dataframe original\n",
    "df_draft = df_draft.merge(crescimento_por_pdv, on='PDV', how='left')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4bc8c2b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_similares['PDV'] = df_similares['PDV'].astype('Int64')\n",
    "\n",
    "df_final = pd.merge(left=df_similares,right=df_draft,right_on=['PDV', 'SKU'],left_on=['PDV','PRODUTO SIMILAR'],how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "867eef0d",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\joao.herculano\\AppData\\Local\\Temp\\ipykernel_33884\\330515216.py:29: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.\n",
      "  dfi = pd.read_sql(query, conn)\n"
     ]
    }
   ],
   "source": [
    "import pyodbc\n",
    "import configparser\n",
    "\n",
    "\n",
    "config = configparser.ConfigParser()\n",
    "config.read(r\"C:\\Users\\joao.herculano\\Documents\\Enviador de email\\credenciais.ini\")\n",
    "\n",
    "conn = pyodbc.connect(\n",
    "    f\"DRIVER={{SQL Server}};\"\n",
    "    f\"SERVER={config['banco']['host']},1433;\"\n",
    "    f\"DATABASE=GINSENG;\"\n",
    "    f\"UID={config['banco']['user']};\"\n",
    "    f\"PWD={config['banco']['password']}\"\n",
    ")\n",
    "\n",
    "query = '''\n",
    "SELECT \n",
    "    b.[DATA] AS Dia,\n",
    "    b.pdv AS PDV,\n",
    "    b.sku as 'Código do Produto',\n",
    "    b.VENDAS AS Quantidade\n",
    "FROM base_vendas_bi b\n",
    "LEFT JOIN (\n",
    "    SELECT SKU, MAX(ORIGEM) AS ORIGEM\n",
    "    FROM estoque_mar\n",
    "    GROUP BY SKU\n",
    ") e ON b.SKU = e.SKU\n",
    "'''\n",
    "dfi = pd.read_sql(query, conn)\n",
    "conn.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "297526e2",
   "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>Dia</th>\n",
       "      <th>PDV</th>\n",
       "      <th>Código do Produto</th>\n",
       "      <th>Quantidade</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2025-06-02</td>\n",
       "      <td>20998</td>\n",
       "      <td>82113</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2025-06-10</td>\n",
       "      <td>20998</td>\n",
       "      <td>82113</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2025-06-05</td>\n",
       "      <td>20998</td>\n",
       "      <td>85299</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2025-06-06</td>\n",
       "      <td>20998</td>\n",
       "      <td>85299</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2025-06-04</td>\n",
       "      <td>20998</td>\n",
       "      <td>85299</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Dia    PDV  Código do Produto Quantidade\n",
       "0  2025-06-02  20998              82113          0\n",
       "1  2025-06-10  20998              82113          1\n",
       "2  2025-06-05  20998              85299          2\n",
       "3  2025-06-06  20998              85299          0\n",
       "4  2025-06-04  20998              85299          2"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfi.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "80021c11",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_venda_diaria = dfi "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "46accb64",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_venda_diaria['Dia'] = pd.to_datetime(df_venda_diaria['Dia'], errors='coerce').dt.strftime('%d/%m/%Y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c1451562",
   "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>Dia</th>\n",
       "      <th>PDV</th>\n",
       "      <th>Código do Produto</th>\n",
       "      <th>Quantidade</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>02/06/2025</td>\n",
       "      <td>20998</td>\n",
       "      <td>82113</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10/06/2025</td>\n",
       "      <td>20998</td>\n",
       "      <td>82113</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>05/06/2025</td>\n",
       "      <td>20998</td>\n",
       "      <td>85299</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>06/06/2025</td>\n",
       "      <td>20998</td>\n",
       "      <td>85299</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>04/06/2025</td>\n",
       "      <td>20998</td>\n",
       "      <td>85299</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Dia    PDV  Código do Produto Quantidade\n",
       "0  02/06/2025  20998              82113          0\n",
       "1  10/06/2025  20998              82113          1\n",
       "2  05/06/2025  20998              85299          2\n",
       "3  06/06/2025  20998              85299          0\n",
       "4  04/06/2025  20998              85299          2"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#df_venda_diaria = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\EUDORA\\C13\\venda diaria\\FormFiltroConsultaVendaSintetica_10_07_2025_15_27_42.xls\")\n",
    "\n",
    "df_venda_diaria.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7ec747bc",
   "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>Dia</th>\n",
       "      <th>PDV</th>\n",
       "      <th>Código do Produto</th>\n",
       "      <th>Quantidade</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>02/06/2025</td>\n",
       "      <td>20998</td>\n",
       "      <td>82113</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10/06/2025</td>\n",
       "      <td>20998</td>\n",
       "      <td>82113</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>05/06/2025</td>\n",
       "      <td>20998</td>\n",
       "      <td>85299</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>06/06/2025</td>\n",
       "      <td>20998</td>\n",
       "      <td>85299</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>04/06/2025</td>\n",
       "      <td>20998</td>\n",
       "      <td>85299</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Dia    PDV  Código do Produto Quantidade\n",
       "0  02/06/2025  20998              82113          0\n",
       "1  10/06/2025  20998              82113          1\n",
       "2  05/06/2025  20998              85299          2\n",
       "3  06/06/2025  20998              85299          0\n",
       "4  04/06/2025  20998              85299          2"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_venda_diaria.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "05c77fd8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dia                  object\n",
       "PDV                  object\n",
       "Código do Produto     int64\n",
       "Quantidade           object\n",
       "dtype: object"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_venda_diaria.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "eb8e3a26",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_venda_diaria['Quantidade'] = df_venda_diaria['Quantidade'].astype('float')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "882e68aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Dia', 'PDV', 'Código do Produto', 'Quantidade'], dtype='object')"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_venda_diaria.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "c7ddaf20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(6931145, 5)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#df_venda_diaria['PDV'] = df_venda_diaria['Unidade de Negócio'].str.split(\"-\").str[0].str.strip()\n",
    "\n",
    "df_venda_diaria['Dia'] = pd.to_datetime(df_venda_diaria['Dia'], format='%d/%m/%Y')\n",
    "\n",
    "df_venda_diaria = pd.merge(left=df_venda_diaria,right=calendario[['Ciclo','Date']],left_on='Dia',right_on='Date',how='inner')\n",
    "\n",
    "df_venda_diaria = df_venda_diaria.drop(columns='Date')\n",
    "\n",
    "df_venda_diaria.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7119556a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(6931145, 6)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 'Dia' já está em formato datetime, então renomeamos para 'Data' diretamente\n",
    "# ou apenas usamos 'Dia' como referência de data\n",
    "\n",
    "# Ordena o DataFrame para garantir que a cumulativa funcione corretamente\n",
    "df_venda_diaria = df_venda_diaria.sort_values(by=['PDV', 'Código do Produto', 'Dia'])\n",
    "\n",
    "# Calcula a quantidade acumulada até o dia para cada grupo\n",
    "df_venda_diaria['Quantidade Acumulada'] = (\n",
    "    df_venda_diaria\n",
    "    .groupby(['PDV', 'Código do Produto'])['Quantidade']\n",
    "    .cumsum()\n",
    ")  # acumulado por grupo até a data da linha\n",
    "\n",
    "df_venda_diaria.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "c707a1b6",
   "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>PDV</th>\n",
       "      <th>Código do Produto</th>\n",
       "      <th>Ciclo</th>\n",
       "      <th>Quantidade Acumulada</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>11111</td>\n",
       "      <td>48130</td>\n",
       "      <td>C202309</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11201</td>\n",
       "      <td>1004</td>\n",
       "      <td>C202509</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11201</td>\n",
       "      <td>1005</td>\n",
       "      <td>C202509</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>11201</td>\n",
       "      <td>1078</td>\n",
       "      <td>C202509</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>11201</td>\n",
       "      <td>1296</td>\n",
       "      <td>C202509</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2339197</th>\n",
       "      <td>5699</td>\n",
       "      <td>90772</td>\n",
       "      <td>C202511</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2339198</th>\n",
       "      <td>5699</td>\n",
       "      <td>90774</td>\n",
       "      <td>C202511</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2339199</th>\n",
       "      <td>5699</td>\n",
       "      <td>90774</td>\n",
       "      <td>C202512</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2339200</th>\n",
       "      <td>5699</td>\n",
       "      <td>90776</td>\n",
       "      <td>C202511</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2339201</th>\n",
       "      <td>8074</td>\n",
       "      <td>43151</td>\n",
       "      <td>C202505</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2339202 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           PDV  Código do Produto    Ciclo  Quantidade Acumulada\n",
       "0        11111              48130  C202309                   0.0\n",
       "1        11201               1004  C202509                   0.0\n",
       "2        11201               1005  C202509                   0.0\n",
       "3        11201               1078  C202509                   0.0\n",
       "4        11201               1296  C202509                   0.0\n",
       "...        ...                ...      ...                   ...\n",
       "2339197   5699              90772  C202511                   0.0\n",
       "2339198   5699              90774  C202511                   0.0\n",
       "2339199   5699              90774  C202512                   3.0\n",
       "2339200   5699              90776  C202511                   0.0\n",
       "2339201   8074              43151  C202505                   0.0\n",
       "\n",
       "[2339202 rows x 4 columns]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_venda_diaria = df_venda_diaria.drop_duplicates()\n",
    "\n",
    "df_venda_agrupado = df_venda_diaria.groupby(['PDV', 'Código do Produto','Ciclo'])['Quantidade Acumulada'].max().reset_index()\n",
    "df_venda_agrupado"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "e2ae413b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(211020534.731)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_venda_agrupado['Quantidade Acumulada'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "dc452c72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2604, 75)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final = pd.merge(left=df_final, right=filtered_calendario[['Ciclo','INICIO CICLO','FIM CICLO','DURAÇÃO','match','dias_ate_inicio']], right_on='match',left_on='MATCH',how='left')\n",
    "df_final.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "c260e0e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final = df_final.drop(columns=['PDV DESC','status','SKU','Descrição','Lançamento','Item analisado','Planograma','Quantidade por caixa'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "8a05450c",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final = pd.merge(left=df_final, right=calendario[['Ciclo','INICIO CICLO','FIM CICLO','DURAÇÃO']], right_on='Ciclo',left_on='CICLO SIMILAR',how='left')\n",
    "df_final.shape\n",
    "\n",
    "df_final = df_final.drop_duplicates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "cc65edab",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "df_venda_agrupado = df_venda_agrupado.rename(columns={'Quantidade Acumulada':'Vendas Ciclo Lançamento'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "c5cd5f42",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final['PRODUTO LANÇAMENTO'] = df_final['PRODUTO LANÇAMENTO'].astype('Int64')\n",
    "\n",
    "df_venda_agrupado['PDV'] = df_venda_agrupado['PDV'].astype('Int64')\n",
    "\n",
    "df_final = pd.merge(left=df_final, right = df_venda_agrupado, right_on=['Ciclo','Código do Produto','PDV'],left_on=['CICLO SIMILAR','PRODUTO SIMILAR','PDV'],how='left')\n",
    "\n",
    "df_final = df_final.drop_duplicates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "69c88d20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(84)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final['PDV'].value_counts().min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "f5206f50",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Histórico de Vendas do Ciclo 202412',\n",
       "       'Histórico de Vendas do Ciclo 202413',\n",
       "       'Histórico de Vendas do Ciclo 202414',\n",
       "       'Histórico de Vendas do Ciclo 202415',\n",
       "       'Histórico de Vendas do Ciclo 202416',\n",
       "       'Histórico de Vendas do Ciclo 202417',\n",
       "       'Histórico de Vendas do Ciclo 202501',\n",
       "       'Histórico de Vendas do Ciclo 202502',\n",
       "       'Histórico de Vendas do Ciclo 202503',\n",
       "       'Histórico de Vendas do Ciclo 202504',\n",
       "       'Histórico de Vendas do Ciclo 202505',\n",
       "       'Histórico de Vendas do Ciclo 202506',\n",
       "       'Histórico de Vendas do Ciclo 202507',\n",
       "       'Histórico de Vendas do Ciclo 202508',\n",
       "       'Histórico de Vendas do Ciclo 202509',\n",
       "       'Histórico de Vendas do Ciclo 202510',\n",
       "       'Histórico de Vendas do Ciclo 202511'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns[30:47]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "2a049809",
   "metadata": {},
   "outputs": [],
   "source": [
    "colunas = df_final.columns[30:47]\n",
    "\n",
    "df_final[colunas] = df_final[colunas].fillna(0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "0a1bb832",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.0812)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Suponha que os meses estão nas colunas 10 a 26 (17 colunas = 17 meses)\n",
    "colunas_mensais = df_final.columns[30:47]\n",
    "\n",
    "# Passo 1: Soma todas as linhas (itens) por mês → resultado: total por mês\n",
    "soma_mensal = df_final[colunas_mensais].sum()\n",
    "\n",
    "# Passo 2: Calcula a variação percentual de um mês para o outro\n",
    "variacao_mensal = soma_mensal.pct_change()\n",
    "variacao_mensal = variacao_mensal.dropna()\n",
    "\n",
    "variacao_mensal = variacao_mensal[np.isfinite(variacao_mensal)]\n",
    "\n",
    "# Passo 3: Calcula a média da variação (ignorando o primeiro NaN)\n",
    "media_variacao = variacao_mensal[1:].mean()\n",
    "\n",
    "# Calcula média e desvio padrão\n",
    "media = variacao_mensal.mean()\n",
    "desvio = variacao_mensal.std()\n",
    "\n",
    "# Define limite (ex: 2 desvios padrão)\n",
    "limite_superior = media + 2 * desvio\n",
    "limite_inferior = media - 2 * desvio\n",
    "\n",
    "# Filtra dados dentro do limite\n",
    "filtro = variacao_mensal.between(limite_inferior, limite_superior)\n",
    "df_filtrado = variacao_mensal[filtro]\n",
    "CRESCIMENTO = round(df_filtrado.mean(),4)\n",
    "\n",
    "df_final['CRESCIMENTO_GERAL'] = CRESCIMENTO\n",
    "\n",
    "CRESCIMENTO\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "a9647c32",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final = df_final.drop(columns='Ciclo_y')\n",
    "\n",
    "df_final = df_final.rename(columns={'Ciclo_x': 'Ciclo',\t'INICIO CICLO_x': 'INICIO CICLO',\t'FIM CICLO_x':'FIM CICLO' ,'DURAÇÃO_x':'DURAÇÃO',\n",
    "                                    \t'INICIO CICLO_y': 'INICIO CICLO SIMILAR' ,\t'FIM CICLO_y': 'FIM CICLO SIMILAR','DURAÇÃO_y':'DURAÇÃO CICLO SIMILAR'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "8290853c",
   "metadata": {},
   "outputs": [],
   "source": [
    "VENDA_SIMILAR_6_MESES= df_final.columns[40:47]\n",
    "\n",
    "df_final['Pico Vendas Similar Ultimos 6 ciclos'] = df_final[VENDA_SIMILAR_6_MESES].max(axis=1)\n",
    "\n",
    "\n",
    "df_final['MEDIANA DO HISTÓRICO'] = df_final[colunas_mensais].dropna().median(axis=1)\n",
    "\n",
    "df_final['MEDIA DO HISTÓRICO'] = df_final[colunas_mensais].dropna().mean(axis=1)\n",
    "\n",
    "df_final['Vendas Ciclo Lançamento'] = df_final['Vendas Ciclo Lançamento'].fillna(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "d3228386",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final['MEDIANA DO HISTÓRICO USADA'] = np.where(df_final['MEDIA DO HISTÓRICO']<df_final['MEDIANA DO HISTÓRICO'],df_final['MEDIANA DO HISTÓRICO'],df_final['MEDIA DO HISTÓRICO'])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "09cc2f82",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_depara_vdc = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\Vitoria da Conquista\\HISTORICO VENDAS VITORIA DA CONQUISTA\\Filiais - Vitoria da Conquista 4.xlsx\")\n",
    "\n",
    "\n",
    "df_vdc = pd.read_parquet(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\Vitoria da Conquista\\HISTORICO VENDAS VITORIA DA CONQUISTA\\VENDAS VITORIA DA CONQUISTA\\concatenado.parquet\")\n",
    "\n",
    "df_vdc['PDV'] = df_vdc['Quebra'].str.split(\" -\").str[0]\n",
    "\n",
    "df_vdc['PDV'] = df_vdc['PDV'].astype('int64')\n",
    "\n",
    "df_vdc = df_vdc.rename(columns={'Quebra2':'DATA VENDA'})\n",
    "\n",
    "df_vdc['DATA VENDA'] = pd.to_datetime(df_vdc['DATA VENDA'], format='%d/%m/%Y')\n",
    "\n",
    "df_vdc = pd.merge(df_vdc,df_depara_vdc[['CP VIVA BEM','PDVDEPARA.Practico']],left_on='PDV',right_on='CP VIVA BEM',how='inner')\n",
    "\n",
    "df_vdc['Quantidade'] = df_vdc['Quantidade'].str.replace(r',000$','',regex=True)\n",
    "\n",
    "df_vdc['Quantidade'] = df_vdc['Quantidade'].astype('Int64') \n",
    "\n",
    "########################################\n",
    "df_vdc['Quantidade Acumulada vdc'] = (\n",
    "        df_vdc\n",
    "        .groupby(['PDVDEPARA.Practico', 'Código'])['Quantidade']\n",
    "        .cumsum())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6ec5f887",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "6bc460bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    23713\n",
       "1    23713\n",
       "2    23713\n",
       "3    23713\n",
       "4    23713\n",
       "Name: PDVDEPARA.Practico, dtype: object"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_vdc['PDVDEPARA.Practico'] = df_vdc['PDVDEPARA.Practico'].astype(str).str.replace(r'\\.0$', '', regex=True)\n",
    "\n",
    "df_vdc['PDVDEPARA.Practico'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "5a827c08",
   "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>PDVDEPARA.Practico</th>\n",
       "      <th>Código</th>\n",
       "      <th>Ciclo vdc</th>\n",
       "      <th>Quantidade Acumulada vdc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>23701</td>\n",
       "      <td>1004</td>\n",
       "      <td>C202301</td>\n",
       "      <td>164.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>23701</td>\n",
       "      <td>1004</td>\n",
       "      <td>C202302</td>\n",
       "      <td>167.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>23701</td>\n",
       "      <td>1004</td>\n",
       "      <td>C202303</td>\n",
       "      <td>170.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>23701</td>\n",
       "      <td>1004</td>\n",
       "      <td>C202304</td>\n",
       "      <td>173.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>23701</td>\n",
       "      <td>1004</td>\n",
       "      <td>C202305</td>\n",
       "      <td>180.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  PDVDEPARA.Practico  Código Ciclo vdc  Quantidade Acumulada vdc\n",
       "0              23701    1004   C202301                     164.0\n",
       "1              23701    1004   C202302                     167.0\n",
       "2              23701    1004   C202303                     170.0\n",
       "3              23701    1004   C202304                     173.0\n",
       "4              23701    1004   C202305                     180.0"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_vdc = pd.merge(left=df_vdc,right=calendario[['Date','Ciclo']],left_on='DATA VENDA',right_on='Date',how='inner')\n",
    "\n",
    "df_vdc_agrupado = df_vdc.groupby(['PDVDEPARA.Practico',\t'Código','Ciclo'])['Quantidade Acumulada vdc'].max().reset_index()\n",
    "\n",
    "df_vdc_agrupado = df_vdc_agrupado.rename(columns={'Ciclo':'Ciclo vdc'})\n",
    "\n",
    "df_vdc_agrupado['PDVDEPARA.Practico'] = df_vdc_agrupado['PDVDEPARA.Practico'].fillna(0)\n",
    "\n",
    "df_vdc_agrupado.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "e01b2f8d",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_vdc_agrupado = df_vdc_agrupado[df_vdc_agrupado['PDVDEPARA.Practico'] != 'nan']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "4861b401",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_vdc_agrupado['PDVDEPARA.Practico'] = df_vdc_agrupado['PDVDEPARA.Practico'].astype('Int64')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "8ec14143",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final = pd.merge(left=df_final, right = df_vdc_agrupado, right_on=['Ciclo vdc','Código','PDVDEPARA.Practico'],left_on=['CICLO SIMILAR','PRODUTO SIMILAR','PDV'],how='left')\n",
    "\n",
    "df_final['Quantidade Acumulada vdc'] = df_final['Quantidade Acumulada vdc'].fillna(0)\n",
    "\n",
    "\n",
    "df_final['Vendas Ciclo Lançamento'] = np.where(df_final['Quantidade Acumulada vdc']>0, df_final['Quantidade Acumulada vdc'], df_final['Vendas Ciclo Lançamento'])\n",
    "\n",
    "df_final = df_final.drop(columns='Quantidade Acumulada vdc')\n",
    "\n",
    "\n",
    "df_final = df_final.drop(columns='Ciclo vdc')\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "b107e519",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Histórico de Vendas do Ciclo 202505',\n",
       "       'Histórico de Vendas do Ciclo 202506',\n",
       "       'Histórico de Vendas do Ciclo 202507',\n",
       "       'Histórico de Vendas do Ciclo 202508',\n",
       "       'Histórico de Vendas do Ciclo 202509',\n",
       "       'Histórico de Vendas do Ciclo 202510',\n",
       "       'Histórico de Vendas do Ciclo 202511'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns[40:47]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "07f043f2",
   "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>CANAL</th>\n",
       "      <th>UF</th>\n",
       "      <th>med_por_canal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CD</td>\n",
       "      <td>AL</td>\n",
       "      <td>60.176471</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HIB</td>\n",
       "      <td>AL</td>\n",
       "      <td>15.117647</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HIB</td>\n",
       "      <td>BA</td>\n",
       "      <td>0.941176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HIB</td>\n",
       "      <td>BA3</td>\n",
       "      <td>0.470588</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>HIB</td>\n",
       "      <td>SE</td>\n",
       "      <td>6.941176</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>HIB</td>\n",
       "      <td>VDC</td>\n",
       "      <td>0.411765</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>VD</td>\n",
       "      <td>AL</td>\n",
       "      <td>42.705882</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>VD</td>\n",
       "      <td>BA</td>\n",
       "      <td>1.588235</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>VD</td>\n",
       "      <td>BA3</td>\n",
       "      <td>0.823529</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>VD</td>\n",
       "      <td>SE</td>\n",
       "      <td>26.352941</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>VD</td>\n",
       "      <td>VDC</td>\n",
       "      <td>2.647059</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   CANAL   UF  med_por_canal\n",
       "0     CD   AL      60.176471\n",
       "1    HIB   AL      15.117647\n",
       "2    HIB   BA       0.941176\n",
       "3    HIB  BA3       0.470588\n",
       "4    HIB   SE       6.941176\n",
       "5    HIB  VDC       0.411765\n",
       "6     VD   AL      42.705882\n",
       "7     VD   BA       1.588235\n",
       "8     VD  BA3       0.823529\n",
       "9     VD   SE      26.352941\n",
       "10    VD  VDC       2.647059"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "medi = df_final.groupby(['CANAL','UF'])['MEDIANA DO HISTÓRICO USADA'].max().reset_index()\n",
    "medi = medi.rename(columns={'MEDIANA DO HISTÓRICO USADA':'med_por_canal'})\n",
    "medi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "94abddce",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final = pd.merge(left=df_final, right=medi,on=['CANAL','UF'],how='inner')\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "27906593",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final['CRESCIMENTO_FINAL'] = df_final['CRESCIMENTO_GERAL'] + CRESCIMENTO #crescimento do pdv\n",
    "\n",
    "df_final['CRESCIMENTO_FINAL'] = np.where(df_final['CRESCIMENTO_GERAL'] + CRESCIMENTO>0.8,0.8,df_final['CRESCIMENTO_GERAL'] + CRESCIMENTO)\n",
    "\n",
    "df_final['CRESCIMENTO_FINAL'] = np.where(df_final['CRESCIMENTO_GERAL'] + df_final['CRESCIMENTO']<0,0,df_final['CRESCIMENTO_GERAL'] + df_final['CRESCIMENTO'])\n",
    "\n",
    "#df_final['MEDIANA DO HISTÓRICO USADA'] = np.where(df_final['MEDIANA DO HISTÓRICO']==0, df_final['med_por_canal'],df_final['MEDIANA DO HISTÓRICO'])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "5ba0586e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int64(0)"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final['med_por_canal'].isna().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "1a625e69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2604, 91)"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# Primeiro cálculo intermediário\n",
    "df_final['PV GINSENG'] = np.where(df_final['CRESCIMENTO_FINAL'] * df_final['Vendas Ciclo Lançamento'] + df_final['Vendas Ciclo Lançamento'] < df_final['MEDIANA DO HISTÓRICO USADA'],\n",
    "                                    round(df_final['CRESCIMENTO_FINAL'] * df_final['MEDIANA DO HISTÓRICO USADA']+ df_final['MEDIANA DO HISTÓRICO USADA'],0), \n",
    "                                    round(df_final['CRESCIMENTO_FINAL']*df_final['Vendas Ciclo Lançamento']+df_final['Vendas Ciclo Lançamento'],0))\n",
    "\n",
    "df_final['PV GINSENG'] = np.where(df_final['PV GINSENG'].isna(),df_final['med_por_canal'] ,df_final['PV GINSENG'])\n",
    "\n",
    "df_final.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "ad10c069",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final.drop(columns=df_final.columns[29:42],inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "f9bddbb1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['PRODUTO LANÇAMENTO', 'DESCRIÇÃO DO LANÇAMENTO', 'PRODUTO SIMILAR',\n",
       "       'DESCRIÇÃO SIMILAR', 'CICLO SIMILAR', 'FOCO', 'IAF', 'CATEGORIA',\n",
       "       'MARCA', '% CONSUMIDOR', 'MECANICA CONSUMIDOR', '% REVENDEDOR',\n",
       "       'MECANICA REVENDEDOR', 'TIPO DE PRODUTO', 'CAMPANHA', 'MATCH', 'PDV',\n",
       "       'CANAL', 'DESCRIÇÃO PDV', 'PDV DESC', 'UF', 'ANALISTA', 'SUPERVISOR',\n",
       "       'STATUS', 'Classe', 'SKU', 'Descrição', 'Subcategoria', 'Lançamento',\n",
       "       'Histórico de Vendas do Ciclo 202507',\n",
       "       'Histórico de Vendas do Ciclo 202508',\n",
       "       'Histórico de Vendas do Ciclo 202509',\n",
       "       'Histórico de Vendas do Ciclo 202510',\n",
       "       'Histórico de Vendas do Ciclo 202511',\n",
       "       'Histórico de Vendas do Ciclo Atual', 'Dias sem venda',\n",
       "       'Projeção Próximo Ciclo', 'Projeção Próximo Ciclo + 1',\n",
       "       'Promoção Próximo Ciclo', 'Promoção Próximo Ciclo + 1', 'Estoque Atual',\n",
       "       'Estoque em Transito', 'Pedido Pendente',\n",
       "       'Compra inteligente semanal/Sugestão de compra',\n",
       "       'Compra inteligente Próximo Ciclo',\n",
       "       'Compra inteligente Próximo Ciclo + 1', 'Item Desativado',\n",
       "       'Data Prevista Regularização', 'Carteira Bloqueada Para Novos Pedidos',\n",
       "       'Planograma', 'Quantidade por caixa', 'Preço Sell In', 'Quantidade',\n",
       "       'Item analisado', 'match_x', 'CRESCIMENTO', 'Ciclo', 'INICIO CICLO',\n",
       "       'FIM CICLO', 'DURAÇÃO', 'match_y', 'dias_ate_inicio',\n",
       "       'INICIO CICLO SIMILAR', 'FIM CICLO SIMILAR', 'DURAÇÃO CICLO SIMILAR',\n",
       "       'Código do Produto', 'Ciclo', 'Vendas Ciclo Lançamento',\n",
       "       'CRESCIMENTO_GERAL', 'Pico Vendas Similar Ultimos 6 ciclos',\n",
       "       'MEDIANA DO HISTÓRICO', 'MEDIA DO HISTÓRICO',\n",
       "       'MEDIANA DO HISTÓRICO USADA', 'PDVDEPARA.Practico', 'Código',\n",
       "       'med_por_canal', 'CRESCIMENTO_FINAL', 'PV GINSENG'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "fe73c93e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['PRODUTO LANÇAMENTO', 'DESCRIÇÃO DO LANÇAMENTO', 'PRODUTO SIMILAR',\n",
       "       'DESCRIÇÃO SIMILAR', 'CICLO SIMILAR', 'FOCO', 'IAF', 'CATEGORIA',\n",
       "       'MARCA', '% CONSUMIDOR', 'MECANICA CONSUMIDOR', '% REVENDEDOR',\n",
       "       'MECANICA REVENDEDOR', 'TIPO DE PRODUTO', 'CAMPANHA', 'MATCH', 'PDV',\n",
       "       'CANAL', 'DESCRIÇÃO PDV', 'PDV DESC', 'UF', 'ANALISTA', 'SUPERVISOR',\n",
       "       'Descrição', 'Histórico de Vendas do Ciclo 202507',\n",
       "       'Histórico de Vendas do Ciclo 202508',\n",
       "       'Histórico de Vendas do Ciclo 202509',\n",
       "       'Histórico de Vendas do Ciclo 202510',\n",
       "       'Histórico de Vendas do Ciclo 202511',\n",
       "       'Histórico de Vendas do Ciclo Atual', 'Projeção Próximo Ciclo',\n",
       "       'Projeção Próximo Ciclo + 1', 'CRESCIMENTO', 'Vendas Ciclo Lançamento',\n",
       "       'Pico Vendas Similar Ultimos 6 ciclos', 'MEDIANA DO HISTÓRICO',\n",
       "       'MEDIA DO HISTÓRICO', 'MEDIANA DO HISTÓRICO USADA',\n",
       "       'PDVDEPARA.Practico', 'Código', 'PV GINSENG'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "df_final.drop(columns=['STATUS', 'Classe', 'SKU', 'Subcategoria', 'Lançamento',\n",
    "       'Dias sem venda',\n",
    "       #'Projeção Próximo Ciclo', 'Projeção Próximo Ciclo + 1',\n",
    "       'Promoção Próximo Ciclo', 'Promoção Próximo Ciclo + 1', 'Estoque Atual',\n",
    "       'Estoque em Transito', 'Pedido Pendente',\n",
    "       'Compra inteligente semanal/Sugestão de compra',\n",
    "       'Compra inteligente Próximo Ciclo',\n",
    "       'Compra inteligente Próximo Ciclo + 1', 'Item Desativado',\n",
    "       'Data Prevista Regularização', 'Carteira Bloqueada Para Novos Pedidos',\n",
    "       'Planograma', 'Quantidade por caixa', 'Preço Sell In', 'Quantidade',\n",
    "       'Item analisado', 'match_x',\n",
    "        'Ciclo', 'INICIO CICLO', 'FIM CICLO', 'DURAÇÃO',\n",
    "       'match_y', 'dias_ate_inicio', 'INICIO CICLO SIMILAR','med_por_canal', 'CRESCIMENTO_FINAL',\n",
    "       'FIM CICLO SIMILAR', 'DURAÇÃO CICLO SIMILAR', 'Código do Produto','CRESCIMENTO_GERAL'],inplace=True)\n",
    "df_final.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "66772a9a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Histórico de Vendas do Ciclo 202508',\n",
       "       'Histórico de Vendas do Ciclo 202509',\n",
       "       'Histórico de Vendas do Ciclo 202510',\n",
       "       'Histórico de Vendas do Ciclo 202511',\n",
       "       'Histórico de Vendas do Ciclo Atual'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns[25:30]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "15b7149f",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final = df_final.rename(columns={df_final.columns[25]: \"C-4\", df_final.columns[26]: \"C-3\",df_final.columns[27]: \"C-2\",df_final.columns[28]: \"C-1\",df_final.columns[29]:'VENDAS CICLO ATUAL'})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "9333bc77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['PRODUTO LANÇAMENTO', 'DESCRIÇÃO DO LANÇAMENTO', 'PRODUTO SIMILAR',\n",
       "       'DESCRIÇÃO SIMILAR', 'CICLO SIMILAR', 'FOCO', 'IAF', 'CATEGORIA',\n",
       "       'MARCA', '% CONSUMIDOR', 'MECANICA CONSUMIDOR', '% REVENDEDOR',\n",
       "       'MECANICA REVENDEDOR', 'TIPO DE PRODUTO', 'CAMPANHA', 'MATCH', 'PDV',\n",
       "       'CANAL', 'DESCRIÇÃO PDV', 'PDV DESC', 'UF', 'ANALISTA', 'SUPERVISOR',\n",
       "       'DESCRIÇÃO', 'C-4', 'C-3', 'C-2', 'C-1', 'VENDAS CICLO ATUAL',\n",
       "       'PROJEÇÃO PRÓXIMO CICLO', 'PROJEÇÃO PRÓXIMO CICLO + 1', 'CRESCIMENTO',\n",
       "       'VENDAS CICLO LANÇAMENTO', 'PICO VENDAS SIMILAR ULTIMOS 6 CICLOS',\n",
       "       'MEDIANA DO HISTÓRICO', 'MEDIA DO HISTÓRICO',\n",
       "       'MEDIANA DO HISTÓRICO USADA', 'PDVDEPARA.PRACTICO', 'CÓDIGO',\n",
       "       'PV GINSENG'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns = df_final.columns.str.upper()\n",
    "\n",
    "df_final.drop(columns=df_final.filter(regex='HISTÓRICO DE VENDAS DO CICLO').columns, inplace=True)\n",
    "\n",
    "df_final.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "5abd4bae",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final = df_final.drop(columns=['DESCRIÇÃO','MEDIANA DO HISTÓRICO'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "62ce5c62",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2604, 38)"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "10975651",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['PRODUTO LANÇAMENTO', 'DESCRIÇÃO DO LANÇAMENTO', 'PRODUTO SIMILAR',\n",
       "       'DESCRIÇÃO SIMILAR', 'CICLO SIMILAR', 'FOCO', 'IAF', 'CATEGORIA',\n",
       "       'MARCA', '% CONSUMIDOR', 'MECANICA CONSUMIDOR', '% REVENDEDOR',\n",
       "       'MECANICA REVENDEDOR', 'TIPO DE PRODUTO', 'CAMPANHA', 'MATCH', 'PDV',\n",
       "       'CANAL', 'DESCRIÇÃO PDV', 'PDV DESC', 'UF', 'ANALISTA', 'SUPERVISOR',\n",
       "       'C-4', 'C-3', 'C-2', 'C-1', 'VENDAS CICLO ATUAL',\n",
       "       'PROJEÇÃO PRÓXIMO CICLO', 'PROJEÇÃO PRÓXIMO CICLO + 1', 'CRESCIMENTO',\n",
       "       'VENDAS CICLO LANÇAMENTO', 'PICO VENDAS SIMILAR ULTIMOS 6 CICLOS',\n",
       "       'MEDIA DO HISTÓRICO', 'MEDIANA DO HISTÓRICO USADA',\n",
       "       'PDVDEPARA.PRACTICO', 'CÓDIGO', 'PV GINSENG'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "6109c1ea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.0812)"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CRESCIMENTO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "25cbff26",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final = df_final.reindex(columns=[\n",
    "    'SUPERVISOR',\n",
    "    'CANAL',\n",
    "    'UF',\n",
    "    'PDV',\n",
    "    'PDV DESC',\n",
    "    'PRODUTO LANÇAMENTO',\n",
    "    'DESCRIÇÃO DO LANÇAMENTO',\n",
    "    'MARCA',\n",
    "    'CATEGORIA',\n",
    "    'MECANICA CONSUMIDOR',\n",
    "    '% CONSUMIDOR',\n",
    "    'MECANICA REVENDEDOR',\n",
    "    '% REVENDEDOR',\n",
    "    'TIPO DE PRODUTO',\n",
    "    'IAF',\n",
    "    'FOCO',\n",
    "    'PRODUTO SIMILAR',\n",
    "    'DESCRIÇÃO SIMILAR',\n",
    "    'CICLO SIMILAR',\n",
    "    'VENDAS CICLO LANÇAMENTO',\n",
    "    'C-4',\n",
    "    'C-3',\n",
    "    'C-2',\n",
    "    'C-1',\n",
    "    'VENDAS CICLO ATUAL',\n",
    "    'PICO VENDAS SIMILAR ULTIMOS 6 CICLOS',\n",
    "    'PV GINSENG',\n",
    "    'PROJEÇÃO PRÓXIMO CICLO',\n",
    "    'PROJEÇÃO PRÓXIMO CICLO + 1',\n",
    "    ])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "a3e80cb4",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final['SUGESTÃO METASELLIN'] = ''\n",
    "df_final['SUGESTÃO ABASTECIMENTO'] = ''\n",
    "df_final['SUGESTÃO COMERCIAL'] = ''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "aa11b320",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final['PV GINSENG'] = np.ceil(df_final['PV GINSENG'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "2df3e2e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final.to_excel(r'C:\\Users\\joao.herculano\\Documents\\lançamentosugestEUD2.xlsx',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "391a0e3c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
