{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\joao.herculano\\AppData\\Local\\Temp\\ipykernel_72404\\1229765338.py:39: 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",
      "  df0 = pd.read_sql(query, conn)\n"
     ]
    }
   ],
   "source": [
    "import pyodbc\n",
    "import configparser\n",
    "import pandas as pd\n",
    "import numpy as np \n",
    "from datetime import datetime, time\n",
    "\n",
    "\n",
    "config = configparser.ConfigParser()\n",
    "config.read(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\CODIGOS\\relatório_improdutivo\\credenciais.ini\")\n",
    "\n",
    "# Conexão com o banco\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",
    "#gerar query\n",
    "query = '''\n",
    "SELECT \n",
    "    e.pdv,\n",
    "    e.SKU,\n",
    "    COALESCE(e.SKU_PARA, e.SKU) AS SKU_FINAL,\n",
    "    e.[ESTOQUE ATUAL],\n",
    "    e.[ESTOQUE EM TRANSITO],\n",
    "    e.[PEDIDO PENDENTE],\n",
    "    d.salescurve AS Curva,\n",
    "    e.CATEGORIA,\n",
    "    d.dayswithoutsales AS DiasSemVenda,\n",
    "    d.nextcycleprojection,\n",
    "    d.secondtonextcycleprojection\n",
    "FROM \n",
    "    estoque_mar e  \n",
    "LEFT JOIN draft d \n",
    "    ON d.loja_id = e.PDV \n",
    "   AND d.code = e.SKU\n",
    "'''\n",
    "df0 = pd.read_sql(query, conn)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pdv\n",
       "20997    27525\n",
       "20992    26415\n",
       "20969    26377\n",
       "21007    13285\n",
       "20995    12194\n",
       "         ...  \n",
       "23156     1969\n",
       "24253     1334\n",
       "24254     1331\n",
       "24268     1175\n",
       "24258      941\n",
       "Name: count, Length: 80, dtype: int64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df0['pdv'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\joao.herculano\\AppData\\Local\\Temp\\ipykernel_72404\\1692316838.py:25: 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",
      "  dfv0 = pd.read_sql(query_vendas, conn)\n"
     ]
    }
   ],
   "source": [
    "query_vendas = '''\n",
    "SELECT \n",
    "\tB.PDV, \n",
    "\tB.SKU,\n",
    "\tB.DESCRICAO,\n",
    "\tSUM(CAST(b.VENDAS AS DECIMAL(18,2))) AS VENDAS_CICLO,\n",
    "\tC.Ciclo\n",
    "FROM base_vendas_bi b\n",
    "INNER JOIN ciclos_data_2025 c \n",
    "    ON CAST(b.[DATA] AS DATE) = CONVERT(DATE, c.[Date], 103) AND C.MARCA = 'BOT'\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",
    "WHERE b.[DATA] > '2024-07-28'\n",
    "GROUP BY\n",
    "B.PDV, \n",
    "\tB.SKU,\n",
    "\tB.DESCRICAO,\n",
    "\tC.Ciclo,\n",
    "\tE.ORIGEM \n",
    "'''\n",
    "\n",
    "dfv0 = pd.read_sql(query_vendas, conn)\n",
    "\n",
    "conn.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=df0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "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>SKU</th>\n",
       "      <th>DESCRICAO</th>\n",
       "      <th>VENDAS_CICLO</th>\n",
       "      <th>Ciclo</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>21278</td>\n",
       "      <td>51244</td>\n",
       "      <td>QUASAR DES COL BLUE V4 100ml</td>\n",
       "      <td>7.0</td>\n",
       "      <td>C202512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20993</td>\n",
       "      <td>49418</td>\n",
       "      <td>NSPA OL DES HID CPO QUIN/AMEN 200ml V3</td>\n",
       "      <td>9.0</td>\n",
       "      <td>C202508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>21375</td>\n",
       "      <td>84385</td>\n",
       "      <td>MALBEC EDP SIGNATURE V3 90ml</td>\n",
       "      <td>1.0</td>\n",
       "      <td>C202413</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12820</td>\n",
       "      <td>87373</td>\n",
       "      <td>CBEM SAB BARRA BEIJINHO V3 2x80g</td>\n",
       "      <td>0.0</td>\n",
       "      <td>C202414</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13427</td>\n",
       "      <td>49766</td>\n",
       "      <td>UOMINI DES COL BLACK V6 100ml</td>\n",
       "      <td>2.0</td>\n",
       "      <td>C202412</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     PDV    SKU                               DESCRICAO  VENDAS_CICLO    Ciclo\n",
       "0  21278  51244            QUASAR DES COL BLUE V4 100ml           7.0  C202512\n",
       "1  20993  49418  NSPA OL DES HID CPO QUIN/AMEN 200ml V3           9.0  C202508\n",
       "2  21375  84385            MALBEC EDP SIGNATURE V3 90ml           1.0  C202413\n",
       "3  12820  87373        CBEM SAB BARRA BEIJINHO V3 2x80g           0.0  C202414\n",
       "4  13427  49766           UOMINI DES COL BLACK V6 100ml           2.0  C202412"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfv0.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "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>SKU</th>\n",
       "      <th>DESCRICAO</th>\n",
       "      <th>C202411</th>\n",
       "      <th>C202412</th>\n",
       "      <th>C202413</th>\n",
       "      <th>C202414</th>\n",
       "      <th>C202415</th>\n",
       "      <th>C202416</th>\n",
       "      <th>C202417</th>\n",
       "      <th>...</th>\n",
       "      <th>C202504</th>\n",
       "      <th>C202505</th>\n",
       "      <th>C202506</th>\n",
       "      <th>C202507</th>\n",
       "      <th>C202508</th>\n",
       "      <th>C202509</th>\n",
       "      <th>C202510</th>\n",
       "      <th>C202511</th>\n",
       "      <th>C202512</th>\n",
       "      <th>C202513</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>11201</td>\n",
       "      <td>1004</td>\n",
       "      <td>FLORATTA DES COL MY BLUE 75ml</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11201</td>\n",
       "      <td>1005</td>\n",
       "      <td>DEM FLORATTA DES COL MY BLUE 4ml</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11201</td>\n",
       "      <td>1078</td>\n",
       "      <td>MATCH SRUM CAP POS QUIMICA 50ml</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>11201</td>\n",
       "      <td>1296</td>\n",
       "      <td>PMPCK THE BLEND DES ANTIT AER 2x75g</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>11201</td>\n",
       "      <td>1302</td>\n",
       "      <td>PMPCK LILY DES ANTIT AER 2x75g</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     PDV   SKU                            DESCRICAO  C202411  C202412  \\\n",
       "0  11201  1004        FLORATTA DES COL MY BLUE 75ml      0.0      0.0   \n",
       "1  11201  1005     DEM FLORATTA DES COL MY BLUE 4ml      0.0      0.0   \n",
       "2  11201  1078      MATCH SRUM CAP POS QUIMICA 50ml      0.0      0.0   \n",
       "3  11201  1296  PMPCK THE BLEND DES ANTIT AER 2x75g      0.0      0.0   \n",
       "4  11201  1302       PMPCK LILY DES ANTIT AER 2x75g      0.0      0.0   \n",
       "\n",
       "   C202413  C202414  C202415  C202416  C202417  ...  C202504  C202505  \\\n",
       "0      0.0      0.0      0.0      0.0      0.0  ...      0.0      0.0   \n",
       "1      0.0      0.0      0.0      0.0      0.0  ...      0.0      0.0   \n",
       "2      0.0      0.0      0.0      0.0      0.0  ...      0.0      0.0   \n",
       "3      0.0      0.0      0.0      0.0      0.0  ...      0.0      0.0   \n",
       "4      0.0      0.0      0.0      0.0      0.0  ...      0.0      0.0   \n",
       "\n",
       "   C202506  C202507  C202508  C202509  C202510  C202511  C202512  C202513  \n",
       "0      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "1      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "2      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "3      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "4      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "\n",
       "[5 rows x 23 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# 1. Agrupamento\n",
    "df_agrupado = dfv0.groupby(['PDV', 'SKU', 'DESCRICAO', 'Ciclo'], as_index=False)['VENDAS_CICLO'].sum()\n",
    "\n",
    "# 2. Pivotar o DataFrame\n",
    "df_pivotado = df_agrupado.pivot_table(\n",
    "    index=['PDV', 'SKU', 'DESCRICAO'],\n",
    "    columns='Ciclo',\n",
    "    values='VENDAS_CICLO',\n",
    "    fill_value=0  # Substitui NaN por 0\n",
    ")\n",
    "\n",
    "# 3. Resetar o índice para deixar como DataFrame normal (opcional)\n",
    "df_vendas = df_pivotado.reset_index()\n",
    "\n",
    "# 4. (Opcional) Renomear colunas com prefixo \"Ciclo_\"\n",
    "df_vendas.columns.name = None\n",
    "df_vendas = df_vendas.rename(columns=lambda x: f'Ciclo_{x}' if isinstance(x, (int, str)) and str(x).isdigit() else x)\n",
    "\n",
    "# Resultado final\n",
    "df_vendas.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# O QUE PRECISA PRA RODAR ESSE CÓDIGO:\n",
    "\n",
    "# Arquivo Draft\n",
    "# Arquivo Estoque\n",
    "# Arquivo BI preço\n",
    "# Arquivo pdv\n",
    "# Arquivo Calendario\n",
    "# Arquivo tabela de compra\n",
    "\n",
    "#Atualizar o nome da marca no filtro do estoque."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "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\\EUDORA\\C13\\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",
    "\n",
    "#df_draft.shape\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "#Caminho onde estão as subpastas com os arquivos CSV\n",
    "#pasta_entrada =  r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\EUDORA\\C13\\estoque\"\n",
    "\n",
    "# Lista todas as subpastas dentro de \"ESTOQUE\"\n",
    "#subpastas = [os.path.join(pasta_entrada, d) for d in os.listdir(pasta_entrada) if os.path.isdir(os.path.join(pasta_entrada, d))]\n",
    "\n",
    "#df_list = []\n",
    "\n",
    "# Percorre todas as subpastas\n",
    "#for subpasta in subpastas:\n",
    "#    arquivos = [f for f in os.listdir(subpasta) if f.endswith(\".csv\")]\n",
    "#    nome_pasta = os.path.basename(subpasta)  # Obtém o nome da pasta\n",
    "\n",
    "#    for arquivo in arquivos:\n",
    "#        caminho_arquivo = os.path.join(subpasta, arquivo)\n",
    "#        try:\n",
    "#            df = pd.read_csv(caminho_arquivo, encoding=\"utf-8\", low_memory=False)  # Melhor para grandes volumes de dados\n",
    "#            df[\"Arquivo_Origem\"] = arquivo  # Adiciona o nome do arquivo de origem\n",
    "#            df[\"Pasta_Origem\"] = nome_pasta  # Adiciona o nome da pasta de origem\n",
    "#            df_list.append(df)\n",
    "#        except Exception as e:\n",
    "#            print(f\"Erro ao ler o arquivo {arquivo}: {e}\")\n",
    "\n",
    "#if df_list:\n",
    "#    df_estoque = pd.concat(df_list, ignore_index=True)\n",
    "\n",
    "#df_estoque['PDV'] = df_estoque['PDV'].astype(str)\n",
    "\n",
    "#df_estoque['SKU_FINAL'] = np.where(df_estoque['SKU_PARA'] == \"-\", df_estoque['SKU'], df_estoque['SKU_PARA'])\n",
    "\n",
    "#df_estoque['SKU_FINAL']=df_estoque['SKU_FINAL'].astype(str)'''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\joao.herculano\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\openpyxl\\styles\\stylesheet.py:237: UserWarning: Workbook contains no default style, apply openpyxl's default\n",
      "  warn(\"Workbook contains no default style, apply openpyxl's default\")\n"
     ]
    }
   ],
   "source": [
    "df_bi_preco = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\DB_PROMOÇÕES\\EUDORA\\202511\\preço BI\\TABELA DE PREÇOS (2).xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['SKU1', 'SKU2', 'Descrição', 'MARCA', 'CATEGORIA', 'LINHA', 'UF',\n",
       "       'Tipo Preço', 'PC', 'PV'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_bi_preco.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_pdv = pd.read_excel(r\"C:\\Users\\joao.herculano\\Documents\\PDV_ATT.xlsx\")\n",
    "df_pdv = df_pdv.rename(columns={'DESCRIÇÃO':'DESCRIÇÃO PDV'})\n",
    "df_pdv = df_pdv.drop(columns=['REGIÃO', 'ESTADO','CIDADE','GESTÃO', 'SUPERVISOR'])\n",
    "df_pdv = df_pdv[~df_pdv['CANAL'].isin(['MTZ','LJ'])]\n",
    "df_pdv = df_pdv[df_pdv['STATUS']!= \"INATIVO\"]\n",
    "\n",
    "df_pdv = df_pdv.drop(columns=['STATUS'])\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PDV\n",
       "20968    1\n",
       "20969    1\n",
       "20970    1\n",
       "20986    1\n",
       "20988    1\n",
       "20989    1\n",
       "20991    1\n",
       "20992    1\n",
       "20993    1\n",
       "20994    1\n",
       "20995    1\n",
       "20996    1\n",
       "20997    1\n",
       "20998    1\n",
       "20999    1\n",
       "21000    1\n",
       "21001    1\n",
       "21278    1\n",
       "21375    1\n",
       "21383    1\n",
       "21495    1\n",
       "22541    1\n",
       "23703    1\n",
       "23704    1\n",
       "23711    1\n",
       "23712    1\n",
       "24255    1\n",
       "24257    1\n",
       "24269    1\n",
       "24293    1\n",
       "23813    1\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_pdv['PDV'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_pdv['MATCH'] = 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**ALTERAR NOME DA COLUNA \"ARQUIVO_ORIGEM\" PARA UMA DAS OPÇÕES ABAIXO:**\n",
    "\n",
    "*BOT.csv* \n",
    "\n",
    "*EUD.csv*\n",
    "\n",
    "*QDB.csv*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_estoque = df_estoque[df_estoque['Arquivo_Origem']== \"EUD.csv\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "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\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "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",
    "calendario['ANO_CICLO'] = calendario['Ciclo'].str[0:5]\n",
    "\n",
    "\n",
    "calendario = calendario[calendario['MARCA'] == \"EUDORA\"]\n",
    "\n",
    "calendario['CICLOMAIS2'] = calendario['ANO_CICLO'].astype(str) + (calendario['NUM_CICLO'].astype(int) + 2).astype(str).str.zfill(2)\n",
    "\n",
    "ciclo_mais2 = calendario[calendario['Date'].dt.normalize() == today]['CICLOMAIS2'].iloc[0]\n",
    "\n",
    "\n",
    "# Filter rows where date matches today\n",
    "filtered_calendario = calendario[calendario['Ciclo'] == ciclo_mais2][:1]\n",
    "\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"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "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",
       "    </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>C202517</td>\n",
       "      <td>35</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  \n",
       "2430     C2025    C202517               35  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filtered_calendario"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "filtered_calendario['match'] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_pdv['UF'] = np.where(df_pdv['UF'] == 'VDC','BA',df_pdv['UF'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\DB_PROMOÇÕES\\EUDORA\\202515\\tabela promo\\Tabela-de-Promocao_C15-1755294384452.xlsx.xlsx\",skiprows=1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "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>Veiculo</th>\n",
       "      <th>Tipo de Promoção</th>\n",
       "      <th>Estratégia de Promoção</th>\n",
       "      <th>Tipo_mecanica</th>\n",
       "      <th>Promo Período Limitado?</th>\n",
       "      <th>EAM</th>\n",
       "      <th>Categoria</th>\n",
       "      <th>Cód. Combo</th>\n",
       "      <th>Código do Item</th>\n",
       "      <th>...</th>\n",
       "      <th>0.34.2</th>\n",
       "      <th>0.35.2</th>\n",
       "      <th>0.2.3</th>\n",
       "      <th>0.25.3</th>\n",
       "      <th>0.28.3</th>\n",
       "      <th>0.3.3</th>\n",
       "      <th>0.32.3</th>\n",
       "      <th>0.34.3</th>\n",
       "      <th>0.35.3</th>\n",
       "      <th>BSO</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>...</td>\n",
       "      <td>28.87</td>\n",
       "      <td>29.72</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.28</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.32</td>\n",
       "      <td>0.34</td>\n",
       "      <td>0.35</td>\n",
       "      <td>Sim</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>202515</td>\n",
       "      <td>Guia CF</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>52107</td>\n",
       "      <td>...</td>\n",
       "      <td>33.97</td>\n",
       "      <td>34.97</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.28</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.32</td>\n",
       "      <td>0.34</td>\n",
       "      <td>0.35</td>\n",
       "      <td>Sim</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>202515</td>\n",
       "      <td>Guia CF</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>50271</td>\n",
       "      <td>...</td>\n",
       "      <td>23.77</td>\n",
       "      <td>24.47</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.28</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.32</td>\n",
       "      <td>0.34</td>\n",
       "      <td>0.35</td>\n",
       "      <td>Sim</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>202515</td>\n",
       "      <td>Guia CF</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>57550</td>\n",
       "      <td>...</td>\n",
       "      <td>27.17</td>\n",
       "      <td>27.97</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.28</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.32</td>\n",
       "      <td>0.34</td>\n",
       "      <td>0.35</td>\n",
       "      <td>Sim</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>202515</td>\n",
       "      <td>Guia CF</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>52943</td>\n",
       "      <td>...</td>\n",
       "      <td>35.67</td>\n",
       "      <td>36.72</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.28</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.32</td>\n",
       "      <td>0.34</td>\n",
       "      <td>0.35</td>\n",
       "      <td>Sim</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 47 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Ciclo    Veiculo Tipo de Promoção Estratégia de Promoção    Tipo_mecanica  \\\n",
       "0  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "1  202515    Guia CF      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "2  202515    Guia CF      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "3  202515    Guia CF      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "4  202515    Guia CF      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "\n",
       "  Promo Período Limitado?  EAM       Categoria  Cód. Combo  Código do Item  \\\n",
       "0           13/10 a 25/10  Não  PERF. FEMININA         NaN           94060   \n",
       "1                     NaN  Não  PERF. FEMININA         NaN           52107   \n",
       "2                     NaN  Não  PERF. FEMININA         NaN           50271   \n",
       "3                     NaN  Não  PERF. FEMININA         NaN           57550   \n",
       "4                     NaN  Não  PERF. FEMININA         NaN           52943   \n",
       "\n",
       "   ... 0.34.2 0.35.2  0.2.3  0.25.3  0.28.3  0.3.3  0.32.3  0.34.3  0.35.3  \\\n",
       "0  ...  28.87  29.72    0.2    0.25    0.28    0.3    0.32    0.34    0.35   \n",
       "1  ...  33.97  34.97    0.2    0.25    0.28    0.3    0.32    0.34    0.35   \n",
       "2  ...  23.77  24.47    0.2    0.25    0.28    0.3    0.32    0.34    0.35   \n",
       "3  ...  27.17  27.97    0.2    0.25    0.28    0.3    0.32    0.34    0.35   \n",
       "4  ...  35.67  36.72    0.2    0.25    0.28    0.3    0.32    0.34    0.35   \n",
       "\n",
       "   BSO  \n",
       "0  Sim  \n",
       "1  Sim  \n",
       "2  Sim  \n",
       "3  Sim  \n",
       "4  Sim  \n",
       "\n",
       "[5 rows x 47 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tabela.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela = df_tabela[[    'Ciclo',                 'Veiculo',\n",
    "              'Tipo de Promoção',  'Estratégia de Promoção',\n",
    "                 'Tipo_mecanica', 'Promo Período Limitado?',\n",
    "                           'EAM',               'Categoria',\n",
    "                    'Cód. Combo',          'Código do Item',\n",
    "             'Descrição do Item',     'Chamada Promocional',\n",
    "                 'Valor do Guia',      'Preço Promocionado',\n",
    "                 '% de Desconto',           'RE compra por',\n",
    "                  'RE Vende por',          'RE lucra  (R$)']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela['Código do Item'] = df_tabela['Código do Item'].astype(str).str.replace(\".0\",\"\",regex=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "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>Veiculo</th>\n",
       "      <th>Tipo de Promoção</th>\n",
       "      <th>Estratégia de Promoção</th>\n",
       "      <th>Tipo_mecanica</th>\n",
       "      <th>Promo Período Limitado?</th>\n",
       "      <th>EAM</th>\n",
       "      <th>Categoria</th>\n",
       "      <th>Cód. Combo</th>\n",
       "      <th>Código do Item</th>\n",
       "      <th>Descrição do Item</th>\n",
       "      <th>Chamada Promocional</th>\n",
       "      <th>Valor do Guia</th>\n",
       "      <th>Preço Promocionado</th>\n",
       "      <th>% de Desconto</th>\n",
       "      <th>RE compra por</th>\n",
       "      <th>RE Vende por</th>\n",
       "      <th>RE lucra  (R$)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.90</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>202515</td>\n",
       "      <td>Guia CF</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>52107</td>\n",
       "      <td>EUDORA DIVA FABULOSA DESODORANTE COLONIA 100ML</td>\n",
       "      <td>EUDORA DIVA FABULOSA DESODORANTE COLONIA 100ML...</td>\n",
       "      <td>139.90</td>\n",
       "      <td>99.9</td>\n",
       "      <td>0.286</td>\n",
       "      <td>69.93</td>\n",
       "      <td>99.9</td>\n",
       "      <td>29.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>202515</td>\n",
       "      <td>Guia CF</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>50271</td>\n",
       "      <td>EUDORA DESODORANTE COLÔNIA KISS ME NOW 50ml VE...</td>\n",
       "      <td>EUDORA DESODORANTE COLÔNIA KISS ME NOW 50ml VE...</td>\n",
       "      <td>99.99</td>\n",
       "      <td>69.9</td>\n",
       "      <td>0.301</td>\n",
       "      <td>48.93</td>\n",
       "      <td>69.9</td>\n",
       "      <td>20.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>202515</td>\n",
       "      <td>Guia CF</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>57550</td>\n",
       "      <td>EUDORA VELVET MILANO DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>EUDORA VELVET MILANO DESODORANTE COLÔNIA 100ML...</td>\n",
       "      <td>119.90</td>\n",
       "      <td>79.9</td>\n",
       "      <td>0.334</td>\n",
       "      <td>55.93</td>\n",
       "      <td>79.9</td>\n",
       "      <td>23.97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>202515</td>\n",
       "      <td>Guia CF</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>52943</td>\n",
       "      <td>Eudora Magnific Rouge Camélia Des Col 75 ML</td>\n",
       "      <td>Eudora Magnific Rouge Camélia Des Col 75 ML | ...</td>\n",
       "      <td>134.90</td>\n",
       "      <td>104.9</td>\n",
       "      <td>0.222</td>\n",
       "      <td>73.43</td>\n",
       "      <td>104.9</td>\n",
       "      <td>31.47</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Ciclo    Veiculo Tipo de Promoção Estratégia de Promoção    Tipo_mecanica  \\\n",
       "0  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "1  202515    Guia CF      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "2  202515    Guia CF      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "3  202515    Guia CF      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "4  202515    Guia CF      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "\n",
       "  Promo Período Limitado?  EAM       Categoria  Cód. Combo Código do Item  \\\n",
       "0           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "1                     NaN  Não  PERF. FEMININA         NaN          52107   \n",
       "2                     NaN  Não  PERF. FEMININA         NaN          50271   \n",
       "3                     NaN  Não  PERF. FEMININA         NaN          57550   \n",
       "4                     NaN  Não  PERF. FEMININA         NaN          52943   \n",
       "\n",
       "                                   Descrição do Item  \\\n",
       "0     EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "1     EUDORA DIVA FABULOSA DESODORANTE COLONIA 100ML   \n",
       "2  EUDORA DESODORANTE COLÔNIA KISS ME NOW 50ml VE...   \n",
       "3     EUDORA VELVET MILANO DESODORANTE COLÔNIA 100ML   \n",
       "4        Eudora Magnific Rouge Camélia Des Col 75 ML   \n",
       "\n",
       "                                 Chamada Promocional  Valor do Guia  \\\n",
       "0  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...         119.90   \n",
       "1  EUDORA DIVA FABULOSA DESODORANTE COLONIA 100ML...         139.90   \n",
       "2  EUDORA DESODORANTE COLÔNIA KISS ME NOW 50ml VE...          99.99   \n",
       "3  EUDORA VELVET MILANO DESODORANTE COLÔNIA 100ML...         119.90   \n",
       "4  Eudora Magnific Rouge Camélia Des Col 75 ML | ...         134.90   \n",
       "\n",
       "   Preço Promocionado  % de Desconto  RE compra por  RE Vende por  \\\n",
       "0                84.9          0.292          59.43          84.9   \n",
       "1                99.9          0.286          69.93          99.9   \n",
       "2                69.9          0.301          48.93          69.9   \n",
       "3                79.9          0.334          55.93          79.9   \n",
       "4               104.9          0.222          73.43         104.9   \n",
       "\n",
       "   RE lucra  (R$)  \n",
       "0           25.47  \n",
       "1           29.97  \n",
       "2           20.97  \n",
       "3           23.97  \n",
       "4           31.47  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tabela.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "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>Veiculo</th>\n",
       "      <th>Tipo de Promoção</th>\n",
       "      <th>Estratégia de Promoção</th>\n",
       "      <th>Tipo_mecanica</th>\n",
       "      <th>Promo Período Limitado?</th>\n",
       "      <th>EAM</th>\n",
       "      <th>Categoria</th>\n",
       "      <th>Cód. Combo</th>\n",
       "      <th>Código do Item</th>\n",
       "      <th>Descrição do Item</th>\n",
       "      <th>Chamada Promocional</th>\n",
       "      <th>Valor do Guia</th>\n",
       "      <th>Preço Promocionado</th>\n",
       "      <th>% de Desconto</th>\n",
       "      <th>RE compra por</th>\n",
       "      <th>RE Vende por</th>\n",
       "      <th>RE lucra  (R$)</th>\n",
       "      <th>SKU</th>\n",
       "      <th>SKU_FINAL</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.9</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.9</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.9</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.9</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.9</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Ciclo    Veiculo Tipo de Promoção Estratégia de Promoção    Tipo_mecanica  \\\n",
       "0  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "1  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "2  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "3  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "4  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "\n",
       "  Promo Período Limitado?  EAM       Categoria  Cód. Combo Código do Item  \\\n",
       "0           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "1           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "2           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "3           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "4           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "\n",
       "                                Descrição do Item  \\\n",
       "0  EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "1  EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "2  EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "3  EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "4  EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "\n",
       "                                 Chamada Promocional  Valor do Guia  \\\n",
       "0  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...          119.9   \n",
       "1  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...          119.9   \n",
       "2  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...          119.9   \n",
       "3  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...          119.9   \n",
       "4  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...          119.9   \n",
       "\n",
       "   Preço Promocionado  % de Desconto  RE compra por  RE Vende por  \\\n",
       "0                84.9          0.292          59.43          84.9   \n",
       "1                84.9          0.292          59.43          84.9   \n",
       "2                84.9          0.292          59.43          84.9   \n",
       "3                84.9          0.292          59.43          84.9   \n",
       "4                84.9          0.292          59.43          84.9   \n",
       "\n",
       "   RE lucra  (R$)    SKU SKU_FINAL  \n",
       "0           25.47  94060     94060  \n",
       "1           25.47  94060     94060  \n",
       "2           25.47  94060     94060  \n",
       "3           25.47  94060     94060  \n",
       "4           25.47  94060     94060  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tabela = pd.merge(left=df_tabela,right=df0[['SKU','SKU_FINAL']],left_on='Código do Item',right_on='SKU',how='left')\n",
    "df_tabela.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela['Código do Item'] = np.where(df_tabela['SKU_FINAL'].notna(),df_tabela['SKU_FINAL'],df_tabela['Código do Item'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela = df_tabela.drop(columns=['SKU','SKU_FINAL'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "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>Veiculo</th>\n",
       "      <th>Tipo de Promoção</th>\n",
       "      <th>Estratégia de Promoção</th>\n",
       "      <th>Tipo_mecanica</th>\n",
       "      <th>Promo Período Limitado?</th>\n",
       "      <th>EAM</th>\n",
       "      <th>Categoria</th>\n",
       "      <th>Cód. Combo</th>\n",
       "      <th>Código do Item</th>\n",
       "      <th>Descrição do Item</th>\n",
       "      <th>Chamada Promocional</th>\n",
       "      <th>Valor do Guia</th>\n",
       "      <th>Preço Promocionado</th>\n",
       "      <th>% de Desconto</th>\n",
       "      <th>RE compra por</th>\n",
       "      <th>RE Vende por</th>\n",
       "      <th>RE lucra  (R$)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.9</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.9</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.9</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.9</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML</td>\n",
       "      <td>FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...</td>\n",
       "      <td>119.9</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Ciclo    Veiculo Tipo de Promoção Estratégia de Promoção    Tipo_mecanica  \\\n",
       "0  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "1  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "2  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "3  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "4  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "\n",
       "  Promo Período Limitado?  EAM       Categoria  Cód. Combo Código do Item  \\\n",
       "0           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "1           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "2           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "3           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "4           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "\n",
       "                                Descrição do Item  \\\n",
       "0  EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "1  EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "2  EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "3  EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "4  EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML   \n",
       "\n",
       "                                 Chamada Promocional  Valor do Guia  \\\n",
       "0  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...          119.9   \n",
       "1  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...          119.9   \n",
       "2  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...          119.9   \n",
       "3  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...          119.9   \n",
       "4  FGCF MOVIMENTO AUTO CUIDADO (13 a 25 OUTUBRO) ...          119.9   \n",
       "\n",
       "   Preço Promocionado  % de Desconto  RE compra por  RE Vende por  \\\n",
       "0                84.9          0.292          59.43          84.9   \n",
       "1                84.9          0.292          59.43          84.9   \n",
       "2                84.9          0.292          59.43          84.9   \n",
       "3                84.9          0.292          59.43          84.9   \n",
       "4                84.9          0.292          59.43          84.9   \n",
       "\n",
       "   RE lucra  (R$)  \n",
       "0           25.47  \n",
       "1           25.47  \n",
       "2           25.47  \n",
       "3           25.47  \n",
       "4           25.47  "
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tabela.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela['MATCH'] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela = pd.merge(left=df_tabela,right=df_pdv[['PDV','MATCH','UF','DESCRIÇÃO PDV','ANALISTA']],on='MATCH',how='inner')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "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>Veiculo</th>\n",
       "      <th>Tipo de Promoção</th>\n",
       "      <th>Estratégia de Promoção</th>\n",
       "      <th>Tipo_mecanica</th>\n",
       "      <th>Promo Período Limitado?</th>\n",
       "      <th>EAM</th>\n",
       "      <th>Categoria</th>\n",
       "      <th>Cód. Combo</th>\n",
       "      <th>Código do Item</th>\n",
       "      <th>...</th>\n",
       "      <th>Preço Promocionado</th>\n",
       "      <th>% de Desconto</th>\n",
       "      <th>RE compra por</th>\n",
       "      <th>RE Vende por</th>\n",
       "      <th>RE lucra  (R$)</th>\n",
       "      <th>MATCH</th>\n",
       "      <th>PDV</th>\n",
       "      <th>UF</th>\n",
       "      <th>DESCRIÇÃO PDV</th>\n",
       "      <th>ANALISTA</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20968</td>\n",
       "      <td>SE</td>\n",
       "      <td>HIB ITABAIANINHA</td>\n",
       "      <td>MARCYARA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20969</td>\n",
       "      <td>AL</td>\n",
       "      <td>HIB MARECHAL DEOD</td>\n",
       "      <td>THAYLLAN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20970</td>\n",
       "      <td>BA</td>\n",
       "      <td>ER SAO SEBASTIAO</td>\n",
       "      <td>DARLIN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20986</td>\n",
       "      <td>BA</td>\n",
       "      <td>HIB OLINDINA</td>\n",
       "      <td>LUCAS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>202515</td>\n",
       "      <td>Fora Guia</td>\n",
       "      <td>Promoção CF</td>\n",
       "      <td>Movimentar Flow</td>\n",
       "      <td>Desconto Direto</td>\n",
       "      <td>13/10 a 25/10</td>\n",
       "      <td>Não</td>\n",
       "      <td>PERF. FEMININA</td>\n",
       "      <td>NaN</td>\n",
       "      <td>94060</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20988</td>\n",
       "      <td>BA</td>\n",
       "      <td>HIB QUEIMADAS</td>\n",
       "      <td>DARLIN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Ciclo    Veiculo Tipo de Promoção Estratégia de Promoção    Tipo_mecanica  \\\n",
       "0  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "1  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "2  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "3  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "4  202515  Fora Guia      Promoção CF        Movimentar Flow  Desconto Direto   \n",
       "\n",
       "  Promo Período Limitado?  EAM       Categoria  Cód. Combo Código do Item  \\\n",
       "0           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "1           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "2           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "3           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "4           13/10 a 25/10  Não  PERF. FEMININA         NaN          94060   \n",
       "\n",
       "   ... Preço Promocionado % de Desconto  RE compra por  RE Vende por  \\\n",
       "0  ...               84.9         0.292          59.43          84.9   \n",
       "1  ...               84.9         0.292          59.43          84.9   \n",
       "2  ...               84.9         0.292          59.43          84.9   \n",
       "3  ...               84.9         0.292          59.43          84.9   \n",
       "4  ...               84.9         0.292          59.43          84.9   \n",
       "\n",
       "   RE lucra  (R$)  MATCH    PDV  UF      DESCRIÇÃO PDV  ANALISTA  \n",
       "0           25.47      1  20968  SE   HIB ITABAIANINHA  MARCYARA  \n",
       "1           25.47      1  20969  AL  HIB MARECHAL DEOD  THAYLLAN  \n",
       "2           25.47      1  20970  BA   ER SAO SEBASTIAO    DARLIN  \n",
       "3           25.47      1  20986  BA       HIB OLINDINA     LUCAS  \n",
       "4           25.47      1  20988  BA      HIB QUEIMADAS    DARLIN  \n",
       "\n",
       "[5 rows x 23 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tabela.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela = df_tabela.drop_duplicates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Ciclo', 'Veiculo', 'Tipo de Promoção', 'Estratégia de Promoção',\n",
       "       'Tipo_mecanica', 'Promo Período Limitado?', 'EAM', 'Categoria',\n",
       "       'Cód. Combo', 'Código do Item', 'Descrição do Item',\n",
       "       'Chamada Promocional', 'Valor do Guia', 'Preço Promocionado',\n",
       "       '% de Desconto', 'RE compra por', 'RE Vende por', 'RE lucra  (R$)',\n",
       "       'MATCH', 'PDV', 'UF', 'DESCRIÇÃO PDV', 'ANALISTA'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tabela.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['pdv', 'SKU', 'SKU_FINAL', 'ESTOQUE ATUAL', 'ESTOQUE EM TRANSITO',\n",
       "       'PEDIDO PENDENTE', 'Curva', 'CATEGORIA', 'DiasSemVenda',\n",
       "       'nextcycleprojection', 'secondtonextcycleprojection'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "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>SKU</th>\n",
       "      <th>SKU_FINAL</th>\n",
       "      <th>ESTOQUE ATUAL</th>\n",
       "      <th>ESTOQUE EM TRANSITO</th>\n",
       "      <th>PEDIDO PENDENTE</th>\n",
       "      <th>Curva</th>\n",
       "      <th>CATEGORIA</th>\n",
       "      <th>DiasSemVenda</th>\n",
       "      <th>nextcycleprojection</th>\n",
       "      <th>secondtonextcycleprojection</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20998</td>\n",
       "      <td>51213</td>\n",
       "      <td>51213</td>\n",
       "      <td>92</td>\n",
       "      <td>21</td>\n",
       "      <td>753</td>\n",
       "      <td>B</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>1.0</td>\n",
       "      <td>258.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20998</td>\n",
       "      <td>83960</td>\n",
       "      <td>83960</td>\n",
       "      <td>10</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>DESODORANTES</td>\n",
       "      <td>4.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20998</td>\n",
       "      <td>75293</td>\n",
       "      <td>75293</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>B</td>\n",
       "      <td>MAQUIAGEM</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20998</td>\n",
       "      <td>75888</td>\n",
       "      <td>75888</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>MAQUIAGEM</td>\n",
       "      <td>27.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20998</td>\n",
       "      <td>52898</td>\n",
       "      <td>52898</td>\n",
       "      <td>341</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>B</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>1.0</td>\n",
       "      <td>43.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     pdv    SKU SKU_FINAL ESTOQUE ATUAL ESTOQUE EM TRANSITO PEDIDO PENDENTE  \\\n",
       "0  20998  51213     51213            92                  21             753   \n",
       "1  20998  83960     83960            10                   5               0   \n",
       "2  20998  75293     75293             6                   1               0   \n",
       "3  20998  75888     75888             3                   0               0   \n",
       "4  20998  52898     52898           341                   0               0   \n",
       "\n",
       "  Curva     CATEGORIA  DiasSemVenda  nextcycleprojection  \\\n",
       "0     B    PERFUMARIA           1.0                258.0   \n",
       "1     C  DESODORANTES           4.0                 11.0   \n",
       "2     B     MAQUIAGEM           3.0                  0.0   \n",
       "3     C     MAQUIAGEM          27.0                  0.0   \n",
       "4     B    PERFUMARIA           1.0                 43.0   \n",
       "\n",
       "   secondtonextcycleprojection  \n",
       "0                          0.0  \n",
       "1                          0.0  \n",
       "2                          0.0  \n",
       "3                          0.0  \n",
       "4                          0.0  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['pdv'] = df['pdv'].astype(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['SKU_FINAL'] = df['SKU_FINAL'].astype(str)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela['Código do Item'] = df_tabela['Código do Item'].astype('str')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Ciclo', 'Veiculo', 'Tipo de Promoção', 'Estratégia de Promoção',\n",
       "       'Tipo_mecanica', 'Promo Período Limitado?', 'EAM', 'Categoria',\n",
       "       'Cód. Combo', 'Código do Item', 'Descrição do Item',\n",
       "       'Chamada Promocional', 'Valor do Guia', 'Preço Promocionado',\n",
       "       '% de Desconto', 'RE compra por', 'RE Vende por', 'RE lucra  (R$)',\n",
       "       'MATCH', 'PDV', 'UF', 'DESCRIÇÃO PDV', 'ANALISTA'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tabela.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_tabela['PDV'] = df_tabela['PDV'].astype(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "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>SKU_FINAL</th>\n",
       "      <th>pdv</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>51213</td>\n",
       "      <td>20998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>83960</td>\n",
       "      <td>20998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>75293</td>\n",
       "      <td>20998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>75888</td>\n",
       "      <td>20998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>52898</td>\n",
       "      <td>20998</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  SKU_FINAL    pdv\n",
       "0     51213  20998\n",
       "1     83960  20998\n",
       "2     75293  20998\n",
       "3     75888  20998\n",
       "4     52898  20998"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['SKU_FINAL','pdv']].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "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>SKU</th>\n",
       "      <th>SKU_FINAL</th>\n",
       "      <th>ESTOQUE ATUAL</th>\n",
       "      <th>ESTOQUE EM TRANSITO</th>\n",
       "      <th>PEDIDO PENDENTE</th>\n",
       "      <th>Curva</th>\n",
       "      <th>CATEGORIA</th>\n",
       "      <th>DiasSemVenda</th>\n",
       "      <th>nextcycleprojection</th>\n",
       "      <th>secondtonextcycleprojection</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>793</th>\n",
       "      <td>20991</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10946</th>\n",
       "      <td>20998</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>15</td>\n",
       "      <td>24</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35510</th>\n",
       "      <td>20995</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>13.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45664</th>\n",
       "      <td>20996</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53287</th>\n",
       "      <td>21278</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73547</th>\n",
       "      <td>20969</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>62.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77615</th>\n",
       "      <td>20992</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92374</th>\n",
       "      <td>20968</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92766</th>\n",
       "      <td>21495</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>107035</th>\n",
       "      <td>20997</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109390</th>\n",
       "      <td>24255</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117431</th>\n",
       "      <td>22541</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>393788</th>\n",
       "      <td>21007</td>\n",
       "      <td>93403</td>\n",
       "      <td>93403</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>INFANTIL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          pdv    SKU SKU_FINAL ESTOQUE ATUAL ESTOQUE EM TRANSITO  \\\n",
       "793     20991  93403     93403             0                   1   \n",
       "10946   20998  93403     93403             0                  15   \n",
       "35510   20995  93403     93403             0                   0   \n",
       "45664   20996  93403     93403             0                   0   \n",
       "53287   21278  93403     93403             0                   0   \n",
       "73547   20969  93403     93403             0                   0   \n",
       "77615   20992  93403     93403             0                   0   \n",
       "92374   20968  93403     93403             0                   0   \n",
       "92766   21495  93403     93403             0                   0   \n",
       "107035  20997  93403     93403             0                   0   \n",
       "109390  24255  93403     93403             0                   0   \n",
       "117431  22541  93403     93403             0                   1   \n",
       "393788  21007  93403     93403             0                   0   \n",
       "\n",
       "       PEDIDO PENDENTE Curva CATEGORIA  DiasSemVenda  nextcycleprojection  \\\n",
       "793                 24     C  INFANTIL           5.0                  0.0   \n",
       "10946               24     C  INFANTIL           5.0                  0.0   \n",
       "35510                0     C  INFANTIL          13.0                  0.0   \n",
       "45664                0     C  INFANTIL           1.0                  0.0   \n",
       "53287                0     C  INFANTIL           6.0                  0.0   \n",
       "73547                0     C  INFANTIL          62.0                  0.0   \n",
       "77615                0     C  INFANTIL           0.0                  0.0   \n",
       "92374                3     C  INFANTIL           6.0                  0.0   \n",
       "92766                0     C  INFANTIL           5.0                  0.0   \n",
       "107035               0     C  INFANTIL           1.0                  0.0   \n",
       "109390               0     C  INFANTIL           6.0                  0.0   \n",
       "117431               0     C  INFANTIL           3.0                  0.0   \n",
       "393788               0  None  INFANTIL           NaN                  NaN   \n",
       "\n",
       "        secondtonextcycleprojection  \n",
       "793                             0.0  \n",
       "10946                           0.0  \n",
       "35510                           0.0  \n",
       "45664                           0.0  \n",
       "53287                           0.0  \n",
       "73547                           0.0  \n",
       "77615                           0.0  \n",
       "92374                           0.0  \n",
       "92766                           0.0  \n",
       "107035                          0.0  \n",
       "109390                          0.0  \n",
       "117431                          0.0  \n",
       "393788                          NaN  "
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[(df['SKU_FINAL']=='93403')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10375, 34)"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final = pd.merge(left=df,right=df_tabela,right_on=['Código do Item','PDV'],left_on=['SKU_FINAL','pdv'],how='right')\n",
    "df_final.shape  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final = pd.merge(left=df,right=df_tabela,right_on=['Código do Item','PDV'],left_on=['SKU','pdv'],how='right')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['pdv', 'SKU', 'SKU_FINAL', 'ESTOQUE ATUAL', 'ESTOQUE EM TRANSITO',\n",
       "       'PEDIDO PENDENTE', 'Curva', 'CATEGORIA', 'DiasSemVenda',\n",
       "       'nextcycleprojection', 'secondtonextcycleprojection', 'Ciclo',\n",
       "       'Veiculo', 'Tipo de Promoção', 'Estratégia de Promoção',\n",
       "       'Tipo_mecanica', 'Promo Período Limitado?', 'EAM', 'Categoria',\n",
       "       'Cód. Combo', 'Código do Item', 'Descrição do Item',\n",
       "       'Chamada Promocional', 'Valor do Guia', 'Preço Promocionado',\n",
       "       '% de Desconto', 'RE compra por', 'RE Vende por', 'RE lucra  (R$)',\n",
       "       'MATCH', 'PDV', 'UF', 'DESCRIÇÃO PDV', 'ANALISTA'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final['pdv'] = df_final['PDV']\n",
    "df_final['SKU_FINAL'] = df_final['Código do Item']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML\n",
       "1       EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML\n",
       "2       EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML\n",
       "3       EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML\n",
       "4       EUDORA VELVET DIVINE DESODORANTE COLÔNIA 100ML\n",
       "                             ...                      \n",
       "8923         ESTOJO LA VICTORIE INTENSE NAMORADOS 2025\n",
       "8924         ESTOJO LA VICTORIE INTENSE NAMORADOS 2025\n",
       "8925         ESTOJO LA VICTORIE INTENSE NAMORADOS 2025\n",
       "8926         ESTOJO LA VICTORIE INTENSE NAMORADOS 2025\n",
       "8927         ESTOJO LA VICTORIE INTENSE NAMORADOS 2025\n",
       "Name: Descrição do Item, Length: 8928, dtype: object"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final['Descrição do Item']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "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>SKU</th>\n",
       "      <th>SKU_FINAL</th>\n",
       "      <th>ESTOQUE ATUAL</th>\n",
       "      <th>ESTOQUE EM TRANSITO</th>\n",
       "      <th>PEDIDO PENDENTE</th>\n",
       "      <th>Curva</th>\n",
       "      <th>CATEGORIA</th>\n",
       "      <th>DiasSemVenda</th>\n",
       "      <th>nextcycleprojection</th>\n",
       "      <th>...</th>\n",
       "      <th>Preço Promocionado</th>\n",
       "      <th>% de Desconto</th>\n",
       "      <th>RE compra por</th>\n",
       "      <th>RE Vende por</th>\n",
       "      <th>RE lucra  (R$)</th>\n",
       "      <th>MATCH</th>\n",
       "      <th>PDV</th>\n",
       "      <th>UF</th>\n",
       "      <th>DESCRIÇÃO PDV</th>\n",
       "      <th>ANALISTA</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20968</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20968</td>\n",
       "      <td>SE</td>\n",
       "      <td>HIB ITABAIANINHA</td>\n",
       "      <td>MARCYARA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20969</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>11.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20969</td>\n",
       "      <td>AL</td>\n",
       "      <td>HIB MARECHAL DEOD</td>\n",
       "      <td>THAYLLAN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20970</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20970</td>\n",
       "      <td>BA</td>\n",
       "      <td>ER SAO SEBASTIAO</td>\n",
       "      <td>DARLIN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20986</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20986</td>\n",
       "      <td>BA</td>\n",
       "      <td>HIB OLINDINA</td>\n",
       "      <td>LUCAS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20988</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20988</td>\n",
       "      <td>BA</td>\n",
       "      <td>HIB QUEIMADAS</td>\n",
       "      <td>DARLIN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>20989</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20989</td>\n",
       "      <td>BA</td>\n",
       "      <td>HIB ENTRE RIOS</td>\n",
       "      <td>MARCYARA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>20991</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>30</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20991</td>\n",
       "      <td>AL</td>\n",
       "      <td>HIB CAMPO ALEGRE</td>\n",
       "      <td>THAYLLAN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>20992</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20992</td>\n",
       "      <td>BA</td>\n",
       "      <td>ER CONC COITE</td>\n",
       "      <td>JEFFERSON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>20993</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20993</td>\n",
       "      <td>BA</td>\n",
       "      <td>ER CANDEIAS</td>\n",
       "      <td>DARLIN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>20994</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20994</td>\n",
       "      <td>BA</td>\n",
       "      <td>ER SIMOES FILHO</td>\n",
       "      <td>LUCAS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>20995</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>32.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20995</td>\n",
       "      <td>SE</td>\n",
       "      <td>ER LAGARTO</td>\n",
       "      <td>MARCYARA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>20996</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20996</td>\n",
       "      <td>AL</td>\n",
       "      <td>ER ANTARES</td>\n",
       "      <td>JEFFERSON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>20997</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20997</td>\n",
       "      <td>AL</td>\n",
       "      <td>ER PITANGUINHA</td>\n",
       "      <td>LUCAS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>20998</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20998</td>\n",
       "      <td>AL</td>\n",
       "      <td>CD SERRARIA</td>\n",
       "      <td>VA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>20999</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>17</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>20999</td>\n",
       "      <td>BA</td>\n",
       "      <td>HIB ESPLANADA</td>\n",
       "      <td>MARCYARA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>21000</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>21000</td>\n",
       "      <td>BA</td>\n",
       "      <td>HIB SANTALUZ</td>\n",
       "      <td>DARLIN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>21001</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>21001</td>\n",
       "      <td>BA</td>\n",
       "      <td>HIB RIO REAL</td>\n",
       "      <td>LUCAS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>21278</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>28.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>21278</td>\n",
       "      <td>SE</td>\n",
       "      <td>VD SOCORRO</td>\n",
       "      <td>JEFFERSON</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>21375</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>15</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>21375</td>\n",
       "      <td>BA</td>\n",
       "      <td>IPIRA HB</td>\n",
       "      <td>DARLIN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>21383</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>84.9</td>\n",
       "      <td>0.292</td>\n",
       "      <td>59.43</td>\n",
       "      <td>84.9</td>\n",
       "      <td>25.47</td>\n",
       "      <td>1</td>\n",
       "      <td>21383</td>\n",
       "      <td>BA</td>\n",
       "      <td>CAPIM GROSSO ER</td>\n",
       "      <td>DARLIN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>20 rows × 34 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      pdv    SKU SKU_FINAL ESTOQUE ATUAL ESTOQUE EM TRANSITO PEDIDO PENDENTE  \\\n",
       "0   20968  94060     94060             5                   0               0   \n",
       "1   20969  94060     94060             1                   0               5   \n",
       "2   20970  94060     94060            10                   0               0   \n",
       "3   20986  94060     94060            11                   0               0   \n",
       "4   20988  94060     94060             9                   0               0   \n",
       "5   20989  94060     94060            13                   0               0   \n",
       "6   20991  94060     94060             8                   0              30   \n",
       "7   20992  94060     94060            10                   0               0   \n",
       "8   20993  94060     94060            35                   0               0   \n",
       "9   20994  94060     94060            29                   0               0   \n",
       "10  20995  94060     94060             0                   0               4   \n",
       "11  20996  94060     94060             2                   0               0   \n",
       "12  20997  94060     94060             6                   0              11   \n",
       "13  20998  94060     94060             0                   0              14   \n",
       "14  20999  94060     94060            17                   0               0   \n",
       "15  21000  94060     94060             7                   0               0   \n",
       "16  21001  94060     94060             7                   0               0   \n",
       "17  21278  94060     94060             0                   0               0   \n",
       "18  21375  94060     94060            15                   0               0   \n",
       "19  21383  94060     94060            13                   0               0   \n",
       "\n",
       "   Curva   CATEGORIA  DiasSemVenda  nextcycleprojection  ...  \\\n",
       "0      C  PERFUMARIA          12.0                  0.0  ...   \n",
       "1      C  PERFUMARIA          11.0                  0.0  ...   \n",
       "2      C  PERFUMARIA           3.0                  0.0  ...   \n",
       "3      C  PERFUMARIA           0.0                  0.0  ...   \n",
       "4      C  PERFUMARIA           0.0                  0.0  ...   \n",
       "5      C  PERFUMARIA           0.0                  0.0  ...   \n",
       "6      C  PERFUMARIA           6.0                  0.0  ...   \n",
       "7      C  PERFUMARIA           0.0                  0.0  ...   \n",
       "8      C  PERFUMARIA           1.0                  0.0  ...   \n",
       "9      C  PERFUMARIA           4.0                  0.0  ...   \n",
       "10     C  PERFUMARIA          32.0                  0.0  ...   \n",
       "11     C  PERFUMARIA           4.0                  0.0  ...   \n",
       "12     C  PERFUMARIA           0.0                  0.0  ...   \n",
       "13     C  PERFUMARIA          26.0                  0.0  ...   \n",
       "14     C  PERFUMARIA           4.0                  0.0  ...   \n",
       "15     C  PERFUMARIA           0.0                  0.0  ...   \n",
       "16     C  PERFUMARIA           3.0                  0.0  ...   \n",
       "17     C  PERFUMARIA          28.0                  0.0  ...   \n",
       "18     C  PERFUMARIA           0.0                  0.0  ...   \n",
       "19     C  PERFUMARIA           0.0                  0.0  ...   \n",
       "\n",
       "    Preço Promocionado  % de Desconto RE compra por RE Vende por  \\\n",
       "0                 84.9          0.292         59.43         84.9   \n",
       "1                 84.9          0.292         59.43         84.9   \n",
       "2                 84.9          0.292         59.43         84.9   \n",
       "3                 84.9          0.292         59.43         84.9   \n",
       "4                 84.9          0.292         59.43         84.9   \n",
       "5                 84.9          0.292         59.43         84.9   \n",
       "6                 84.9          0.292         59.43         84.9   \n",
       "7                 84.9          0.292         59.43         84.9   \n",
       "8                 84.9          0.292         59.43         84.9   \n",
       "9                 84.9          0.292         59.43         84.9   \n",
       "10                84.9          0.292         59.43         84.9   \n",
       "11                84.9          0.292         59.43         84.9   \n",
       "12                84.9          0.292         59.43         84.9   \n",
       "13                84.9          0.292         59.43         84.9   \n",
       "14                84.9          0.292         59.43         84.9   \n",
       "15                84.9          0.292         59.43         84.9   \n",
       "16                84.9          0.292         59.43         84.9   \n",
       "17                84.9          0.292         59.43         84.9   \n",
       "18                84.9          0.292         59.43         84.9   \n",
       "19                84.9          0.292         59.43         84.9   \n",
       "\n",
       "   RE lucra  (R$) MATCH    PDV  UF      DESCRIÇÃO PDV   ANALISTA  \n",
       "0           25.47     1  20968  SE   HIB ITABAIANINHA   MARCYARA  \n",
       "1           25.47     1  20969  AL  HIB MARECHAL DEOD   THAYLLAN  \n",
       "2           25.47     1  20970  BA   ER SAO SEBASTIAO     DARLIN  \n",
       "3           25.47     1  20986  BA       HIB OLINDINA      LUCAS  \n",
       "4           25.47     1  20988  BA      HIB QUEIMADAS     DARLIN  \n",
       "5           25.47     1  20989  BA     HIB ENTRE RIOS   MARCYARA  \n",
       "6           25.47     1  20991  AL   HIB CAMPO ALEGRE   THAYLLAN  \n",
       "7           25.47     1  20992  BA      ER CONC COITE  JEFFERSON  \n",
       "8           25.47     1  20993  BA        ER CANDEIAS     DARLIN  \n",
       "9           25.47     1  20994  BA    ER SIMOES FILHO      LUCAS  \n",
       "10          25.47     1  20995  SE         ER LAGARTO   MARCYARA  \n",
       "11          25.47     1  20996  AL         ER ANTARES  JEFFERSON  \n",
       "12          25.47     1  20997  AL     ER PITANGUINHA      LUCAS  \n",
       "13          25.47     1  20998  AL        CD SERRARIA         VA  \n",
       "14          25.47     1  20999  BA      HIB ESPLANADA   MARCYARA  \n",
       "15          25.47     1  21000  BA       HIB SANTALUZ     DARLIN  \n",
       "16          25.47     1  21001  BA       HIB RIO REAL      LUCAS  \n",
       "17          25.47     1  21278  SE         VD SOCORRO  JEFFERSON  \n",
       "18          25.47     1  21375  BA           IPIRA HB     DARLIN  \n",
       "19          25.47     1  21383  BA    CAPIM GROSSO ER     DARLIN  \n",
       "\n",
       "[20 rows x 34 columns]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.head(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final['match'] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8928, 40)"
      ]
     },
     "execution_count": 51,
     "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']], on='match',how='inner')\n",
    "df_final.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PDV\n",
       "20968    288\n",
       "20969    288\n",
       "20970    288\n",
       "20986    288\n",
       "20988    288\n",
       "20989    288\n",
       "20991    288\n",
       "20992    288\n",
       "20993    288\n",
       "20994    288\n",
       "20995    288\n",
       "20996    288\n",
       "20997    288\n",
       "20998    288\n",
       "20999    288\n",
       "21000    288\n",
       "21001    288\n",
       "21278    288\n",
       "21375    288\n",
       "21383    288\n",
       "21495    288\n",
       "22541    288\n",
       "23703    288\n",
       "23704    288\n",
       "23711    288\n",
       "23712    288\n",
       "24255    288\n",
       "24257    288\n",
       "24269    288\n",
       "24293    288\n",
       "23813    288\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.PDV.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8928, 40)"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#df_final = pd.merge(left=df_final,right=df_pdv[['PDV', 'CANAL', 'DESCRIÇÃO PDV', 'PDV DESC','UF', 'MARCA', 'ANALISTA']],on = 'PDV',how='inner')\n",
    "df_final.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final['SKU'] = df_final['SKU'].astype(str) \n",
    "#df_final['PDV'] = df_final['PDV'].astype(str) \n",
    "#df_final = pd.merge(left=df_final,right=df_estoque[['SKU_FINAL', 'DDV PREVISTO', 'COBERTURA ATUAL','PDV']],right_on=['PDV','SKU_FINAL'],left_on=['PDV','SKU'],how='left')\n",
    "#df_final.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"df_bi_preco['SKU2'] = df_bi_preco['SKU2'].astype(str).str.replace('.0','',regex=False) \\n\\ndf_final = pd.merge(left=df_final,right=df_bi_preco[['SKU2', 'UF','Tipo Preço', 'PC', 'PV']],right_on=['UF','SKU2'],left_on=['UF','SKU_FINAL'],how='left')\\ndf_final.shape  \""
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "r'''df_bi_preco['SKU2'] = df_bi_preco['SKU2'].astype(str).str.replace('.0','',regex=False) \n",
    "\n",
    "df_final = pd.merge(left=df_final,right=df_bi_preco[['SKU2', 'UF','Tipo Preço', 'PC', 'PV']],right_on=['UF','SKU2'],left_on=['UF','SKU_FINAL'],how='left')\n",
    "df_final.shape  ''' "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pdv\n",
       "20968    288\n",
       "20969    288\n",
       "20970    288\n",
       "20986    288\n",
       "20988    288\n",
       "20989    288\n",
       "20991    288\n",
       "20992    288\n",
       "20993    288\n",
       "20994    288\n",
       "20995    288\n",
       "20996    288\n",
       "20997    288\n",
       "20998    288\n",
       "20999    288\n",
       "21000    288\n",
       "21001    288\n",
       "21278    288\n",
       "21375    288\n",
       "21383    288\n",
       "21495    288\n",
       "22541    288\n",
       "23703    288\n",
       "23704    288\n",
       "23711    288\n",
       "23712    288\n",
       "24255    288\n",
       "24257    288\n",
       "24269    288\n",
       "24293    288\n",
       "23813    288\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final['pdv'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_bi_preco['SKU1'] = df_bi_preco['SKU1'].astype(str).str.replace('.0','',regex=False) \n",
    "\n",
    "#df_final = pd.merge(left=df_final,right=df_bi_preco[['SKU1', 'SKU2', 'UF', 'PC', 'PV']],right_on=['UF','SKU1'],left_on=['UF','SKU'],how='left')\n",
    "#df_final.shape   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_bi_preco = df_bi_preco[df_bi_preco['MARCA']=='EUDORA']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final['PRECO DE COMPRA'] = np.where(~df_final['PC_x'].isna(),df_final['PC_x'],df_final['PC_y'])\n",
    "\n",
    "#df_final['PRECO DE VENDA'] = np.where(~df_final['PV_x'].isna(),df_final['PV_x'],df_final['PV_y'])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_estoque = df_estoque.rename(columns={'SKU_FINAL':'SKU_PARA_VALIDACAO'})\n",
    "#df_final = pd.merge( left= df_final, right = df_estoque[['SKU_PARA_VALIDACAO','Arquivo_Origem']], left_on= 'SKU', right_on='SKU_PARA_VALIDACAO', how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['pdv', 'SKU', 'SKU_FINAL', 'ESTOQUE ATUAL', 'ESTOQUE EM TRANSITO',\n",
       "       'PEDIDO PENDENTE', 'Curva', 'CATEGORIA', 'DiasSemVenda',\n",
       "       'nextcycleprojection', 'secondtonextcycleprojection', 'Ciclo_x',\n",
       "       'Veiculo', 'Tipo de Promoção', 'Estratégia de Promoção',\n",
       "       'Tipo_mecanica', 'Promo Período Limitado?', 'EAM', 'Categoria',\n",
       "       'Cód. Combo', 'Código do Item', 'Descrição do Item',\n",
       "       'Chamada Promocional', 'Valor do Guia', 'Preço Promocionado',\n",
       "       '% de Desconto', 'RE compra por', 'RE Vende por', 'RE lucra  (R$)',\n",
       "       'MATCH', 'PDV', 'UF', 'DESCRIÇÃO PDV', 'ANALISTA', 'match', 'Ciclo_y',\n",
       "       'INICIO CICLO', 'FIM CICLO', 'DURAÇÃO', 'dias_ate_inicio'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final = df_final.drop(columns=['Desativação','Lançamento','Promoção Próximo Ciclo','Compra inteligente semanal/Sugestão de compra','Planograma','Carteira Bloqueada Para Novos Pedidos','Preço Sell In','Quantidade','Item analisado','Promoção Próximo Ciclo + 1','SKU_PARA_VALIDACAO','Ciclo_y'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8928, 42)"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final['PDV_SKU'] = df_final['PDV'].astype(str) + df_final['SKU_FINAL'].astype(str) \n",
    "df_final['UFPRODUTO'] = df_final['UF'].astype(str) + df_final['SKU_FINAL'].astype(str)\n",
    "\n",
    "df_final.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       20968\n",
       "1       20969\n",
       "2       20970\n",
       "3       20986\n",
       "4       20988\n",
       "        ...  \n",
       "8923    24255\n",
       "8924    24257\n",
       "8925    24269\n",
       "8926    24293\n",
       "8927    23813\n",
       "Name: PDV, Length: 8928, dtype: object"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final['PDV']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "secondtonextcycleprojection\n",
       "0.0     4389\n",
       "1.0       38\n",
       "3.0       30\n",
       "2.0       29\n",
       "4.0       21\n",
       "6.0       20\n",
       "5.0       18\n",
       "19.0      13\n",
       "10.0      12\n",
       "49.0       8\n",
       "27.0       8\n",
       "9.0        8\n",
       "18.0       7\n",
       "34.0       7\n",
       "32.0       5\n",
       "37.0       5\n",
       "8.0        5\n",
       "30.0       5\n",
       "7.0        5\n",
       "17.0       5\n",
       "94.0       4\n",
       "69.0       4\n",
       "11.0       4\n",
       "52.0       4\n",
       "53.0       4\n",
       "98.0       4\n",
       "14.0       3\n",
       "56.0       2\n",
       "15.0       2\n",
       "13.0       2\n",
       "20.0       2\n",
       "44.0       1\n",
       "24.0       1\n",
       "67.0       1\n",
       "23.0       1\n",
       "51.0       1\n",
       "28.0       1\n",
       "41.0       1\n",
       "54.0       1\n",
       "29.0       1\n",
       "16.0       1\n",
       "36.0       1\n",
       "31.0       1\n",
       "12.0       1\n",
       "33.0       1\n",
       "55.0       1\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final['nextcycleprojection'].value_counts()\n",
    "\n",
    "df_final['secondtonextcycleprojection'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final['PROJEÇÃO DO CICLO PROMOCIONADO'] =df_final['Projeção Próximo Ciclo + 1'] - df_final['Projeção Próximo Ciclo'] # projeção do ciclo em estudo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final['PROJEÇÃO DO CICLO PROMOCIONADO'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final['Data Prevista Regularização'] = df_final['Data Prevista Regularização'].astype(str).replace('0','REGULAR')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final = df_final.rename(columns={'Arquivo_Origem': 'MARCA'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final = df_final[~df_final['MARCA'].isna()]\n",
    "#df_final['MARCA'].isna().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8928, 42)"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final = df_final.drop_duplicates()\n",
    "df_final.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['pdv', 'SKU', 'SKU_FINAL', 'ESTOQUE ATUAL', 'ESTOQUE EM TRANSITO',\n",
       "       'PEDIDO PENDENTE', 'Curva', 'CATEGORIA', 'DiasSemVenda',\n",
       "       'nextcycleprojection', 'secondtonextcycleprojection', 'Ciclo_x',\n",
       "       'Veiculo', 'Tipo de Promoção', 'Estratégia de Promoção',\n",
       "       'Tipo_mecanica', 'Promo Período Limitado?', 'EAM', 'Categoria',\n",
       "       'Cód. Combo', 'Código do Item', 'Descrição do Item',\n",
       "       'Chamada Promocional', 'Valor do Guia', 'Preço Promocionado',\n",
       "       '% de Desconto', 'RE compra por', 'RE Vende por', 'RE lucra  (R$)',\n",
       "       'MATCH', 'PDV', 'UF', 'DESCRIÇÃO PDV', 'ANALISTA', 'match', 'Ciclo_y',\n",
       "       'INICIO CICLO', 'FIM CICLO', 'DURAÇÃO', 'dias_ate_inicio', 'PDV_SKU',\n",
       "       'UFPRODUTO'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['PDV', 'SKU', 'DESCRICAO', 'C202411', 'C202412', 'C202413', 'C202414',\n",
       "       'C202415', 'C202416', 'C202417', 'C202501', 'C202502', 'C202503',\n",
       "       'C202504', 'C202505', 'C202506', 'C202507', 'C202508', 'C202509',\n",
       "       'C202510', 'C202511', 'C202512', 'C202513'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_vendas['PDV'] = df_vendas['PDV'].astype(str)\n",
    "df_vendas['SKU'] = df_vendas['SKU'].astype(str)\n",
    "\n",
    "df_vendas.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8928, 42)"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "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>SKU</th>\n",
       "      <th>DESCRICAO</th>\n",
       "      <th>C202411</th>\n",
       "      <th>C202412</th>\n",
       "      <th>C202413</th>\n",
       "      <th>C202414</th>\n",
       "      <th>C202415</th>\n",
       "      <th>C202416</th>\n",
       "      <th>C202417</th>\n",
       "      <th>...</th>\n",
       "      <th>C202504</th>\n",
       "      <th>C202505</th>\n",
       "      <th>C202506</th>\n",
       "      <th>C202507</th>\n",
       "      <th>C202508</th>\n",
       "      <th>C202509</th>\n",
       "      <th>C202510</th>\n",
       "      <th>C202511</th>\n",
       "      <th>C202512</th>\n",
       "      <th>C202513</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>11201</td>\n",
       "      <td>1004</td>\n",
       "      <td>FLORATTA DES COL MY BLUE 75ml</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11201</td>\n",
       "      <td>1005</td>\n",
       "      <td>DEM FLORATTA DES COL MY BLUE 4ml</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>11201</td>\n",
       "      <td>1078</td>\n",
       "      <td>MATCH SRUM CAP POS QUIMICA 50ml</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>11201</td>\n",
       "      <td>1296</td>\n",
       "      <td>PMPCK THE BLEND DES ANTIT AER 2x75g</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>11201</td>\n",
       "      <td>1302</td>\n",
       "      <td>PMPCK LILY DES ANTIT AER 2x75g</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     PDV   SKU                            DESCRICAO  C202411  C202412  \\\n",
       "0  11201  1004        FLORATTA DES COL MY BLUE 75ml      0.0      0.0   \n",
       "1  11201  1005     DEM FLORATTA DES COL MY BLUE 4ml      0.0      0.0   \n",
       "2  11201  1078      MATCH SRUM CAP POS QUIMICA 50ml      0.0      0.0   \n",
       "3  11201  1296  PMPCK THE BLEND DES ANTIT AER 2x75g      0.0      0.0   \n",
       "4  11201  1302       PMPCK LILY DES ANTIT AER 2x75g      0.0      0.0   \n",
       "\n",
       "   C202413  C202414  C202415  C202416  C202417  ...  C202504  C202505  \\\n",
       "0      0.0      0.0      0.0      0.0      0.0  ...      0.0      0.0   \n",
       "1      0.0      0.0      0.0      0.0      0.0  ...      0.0      0.0   \n",
       "2      0.0      0.0      0.0      0.0      0.0  ...      0.0      0.0   \n",
       "3      0.0      0.0      0.0      0.0      0.0  ...      0.0      0.0   \n",
       "4      0.0      0.0      0.0      0.0      0.0  ...      0.0      0.0   \n",
       "\n",
       "   C202506  C202507  C202508  C202509  C202510  C202511  C202512  C202513  \n",
       "0      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "1      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "2      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "3      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "4      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0  \n",
       "\n",
       "[5 rows x 23 columns]"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_vendas.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final = pd.merge(df_final,df_vendas,left_on=['PDV','SKU'],right_on=['PDV','SKU'],how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['pdv', 'SKU', 'SKU_FINAL', 'ESTOQUE ATUAL', 'ESTOQUE EM TRANSITO',\n",
       "       'PEDIDO PENDENTE', 'Curva', 'CATEGORIA', 'DiasSemVenda',\n",
       "       'nextcycleprojection', 'secondtonextcycleprojection', 'Ciclo_x',\n",
       "       'Veiculo', 'Tipo de Promoção', 'Estratégia de Promoção',\n",
       "       'Tipo_mecanica', 'Promo Período Limitado?', 'EAM', 'Categoria',\n",
       "       'Cód. Combo', 'Código do Item', 'Descrição do Item',\n",
       "       'Chamada Promocional', 'Valor do Guia', 'Preço Promocionado',\n",
       "       '% de Desconto', 'RE compra por', 'RE Vende por', 'RE lucra  (R$)',\n",
       "       'MATCH', 'PDV', 'UF', 'DESCRIÇÃO PDV', 'ANALISTA', 'match', 'Ciclo_y',\n",
       "       'INICIO CICLO', 'FIM CICLO', 'DURAÇÃO', 'dias_ate_inicio', 'PDV_SKU',\n",
       "       'UFPRODUTO', 'DESCRICAO', 'C202411', 'C202412', 'C202413', 'C202414',\n",
       "       'C202415', 'C202416', 'C202417', 'C202501', 'C202502', 'C202503',\n",
       "       'C202504', 'C202505', 'C202506', 'C202507', 'C202508', 'C202509',\n",
       "       'C202510', 'C202511', 'C202512', 'C202513'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final.iloc[:, -18:-1] = df_final.iloc[:, -18:-1].fillna(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define list of target columns\n",
    "sales_2024_cols = df_final.columns[-18:-1]\n",
    "# Create a new column with the row-wise max\n",
    "df_final['PICO DE VENDAS 17CICLOS'] = df_final[sales_2024_cols].max(axis=1)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "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>SKU</th>\n",
       "      <th>SKU_FINAL</th>\n",
       "      <th>ESTOQUE ATUAL</th>\n",
       "      <th>ESTOQUE EM TRANSITO</th>\n",
       "      <th>PEDIDO PENDENTE</th>\n",
       "      <th>Curva</th>\n",
       "      <th>CATEGORIA</th>\n",
       "      <th>DiasSemVenda</th>\n",
       "      <th>nextcycleprojection</th>\n",
       "      <th>...</th>\n",
       "      <th>C202505</th>\n",
       "      <th>C202506</th>\n",
       "      <th>C202507</th>\n",
       "      <th>C202508</th>\n",
       "      <th>C202509</th>\n",
       "      <th>C202510</th>\n",
       "      <th>C202511</th>\n",
       "      <th>C202512</th>\n",
       "      <th>C202513</th>\n",
       "      <th>PICO DE VENDAS 17CICLOS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20968</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20969</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>11.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>5.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>43.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20970</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20986</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20988</td>\n",
       "      <td>94060</td>\n",
       "      <td>94060</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>C</td>\n",
       "      <td>PERFUMARIA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 64 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     pdv    SKU SKU_FINAL ESTOQUE ATUAL ESTOQUE EM TRANSITO PEDIDO PENDENTE  \\\n",
       "0  20968  94060     94060             5                   0               0   \n",
       "1  20969  94060     94060             1                   0               5   \n",
       "2  20970  94060     94060            10                   0               0   \n",
       "3  20986  94060     94060            11                   0               0   \n",
       "4  20988  94060     94060             9                   0               0   \n",
       "\n",
       "  Curva   CATEGORIA  DiasSemVenda  nextcycleprojection  ...  C202505  C202506  \\\n",
       "0     C  PERFUMARIA          12.0                  0.0  ...      8.0      0.0   \n",
       "1     C  PERFUMARIA          11.0                  0.0  ...      5.0      3.0   \n",
       "2     C  PERFUMARIA           3.0                  0.0  ...      0.0      0.0   \n",
       "3     C  PERFUMARIA           0.0                  0.0  ...      0.0      0.0   \n",
       "4     C  PERFUMARIA           0.0                  0.0  ...      0.0      0.0   \n",
       "\n",
       "  C202507 C202508 C202509 C202510 C202511 C202512 C202513  \\\n",
       "0     0.0     0.0     0.0     0.0     8.0     2.0     0.0   \n",
       "1     0.0     0.0     0.0     0.0     1.0     3.0     0.0   \n",
       "2     0.0     0.0     0.0     0.0     0.0     2.0     0.0   \n",
       "3     0.0     0.0     0.0     0.0     0.0     0.0     0.0   \n",
       "4     0.0     0.0     0.0     0.0     0.0     0.0     0.0   \n",
       "\n",
       "   PICO DE VENDAS 17CICLOS  \n",
       "0                     11.0  \n",
       "1                     43.0  \n",
       "2                      2.0  \n",
       "3                      0.0  \n",
       "4                      0.0  \n",
       "\n",
       "[5 rows x 64 columns]"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PDV\n",
       "20968    292\n",
       "20969    292\n",
       "20995    292\n",
       "20996    292\n",
       "20997    292\n",
       "20998    292\n",
       "21278    292\n",
       "22541    292\n",
       "21495    291\n",
       "20991    291\n",
       "20989    288\n",
       "20994    288\n",
       "20988    288\n",
       "20986    288\n",
       "20970    288\n",
       "20999    288\n",
       "20992    288\n",
       "20993    288\n",
       "21000    288\n",
       "21375    288\n",
       "21001    288\n",
       "21383    288\n",
       "23703    288\n",
       "23704    288\n",
       "23711    288\n",
       "23712    288\n",
       "24255    288\n",
       "24257    288\n",
       "24269    288\n",
       "24293    288\n",
       "23813    288\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.PDV.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['C202413', 'C202414', 'C202415', 'C202416', 'C202417', 'C202501',\n",
       "       'C202502', 'C202503', 'C202504', 'C202505', 'C202506', 'C202507',\n",
       "       'C202508', 'C202509', 'C202510', 'C202511', 'C202512'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sales_2024_cols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "vendas_6_meses = df_final.columns[-8:-2]\n",
    "\n",
    "df_final['Pico Vendas Ultimos 6 ciclos'] = df_final[vendas_6_meses].max(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C202414'"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns[-19]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.7716087836785548\n"
     ]
    }
   ],
   "source": [
    "CRESCIMENTO = (df_final[df_final.columns[-18]].sum() - df_final[df_final.columns[-3]].sum())/df_final[df_final.columns[-18]].sum() \n",
    "print(CRESCIMENTO)\n",
    "\n",
    "df_final['CRESCIMENTO'] = .2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [],
   "source": [
    "mesmo_ciclo_ano_passado = df_final.columns[-19]\n",
    "ciclo_ano_passado = df_final.columns[-19:-18].str.split(\" \")[0][-1]\n",
    "df_final[ciclo_ano_passado] = df_final[mesmo_ciclo_ano_passado]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C202415'"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns[-19:-18].str.split(\" \")[0][-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['C202413', 'C202414', 'C202415', 'C202416', 'C202417', 'C202501',\n",
       "       'C202502', 'C202503', 'C202504', 'C202505', 'C202506', 'C202507',\n",
       "       'C202508', 'C202509', 'C202510', 'C202511', 'C202512', 'C202513'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns[-21:-3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "vendas_todos_historicos = df_final.columns[-21:-3]\n",
    "\n",
    "df_final['MEDIANA DO HISTÓRICO'] = df_final[vendas_todos_historicos].median(axis=1)\n",
    "\n",
    "df_final['MEDIA DO HISTÓRICO'] = df_final[vendas_todos_historicos].mean(axis=1)\n",
    "\n",
    "df_final['MEDIANA DO HISTÓRICO'] = np.where(df_final['MEDIANA DO HISTÓRICO'] <1,df_final['MEDIA DO HISTÓRICO'],df_final['MEDIANA DO HISTÓRICO'])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.7716087836785548)"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CRESCIMENTO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final['PV GINSENG'] = np.where(df_final['CRESCIMENTO'] * df_final[ciclo_ano_passado] + df_final[ciclo_ano_passado] < df_final['MEDIANA DO HISTÓRICO'],\n",
    "                                    np.ceil(df_final['CRESCIMENTO'] * df_final['MEDIANA DO HISTÓRICO']+ df_final['MEDIANA DO HISTÓRICO']), \n",
    "                                    np.ceil(df_final['CRESCIMENTO']*df_final[ciclo_ano_passado]+df_final[ciclo_ano_passado]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final['PV GINSENG'] = np.where(df_final['PV GINSENG']<1, df_final['Projeção Próximo Ciclo + 1'],df_final['PV GINSENG'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final = df_final.rename(columns={df_final.columns[18]: \"C-4\", df_final.columns[19]: \"C-3\",df_final.columns[20]: \"C-2\",df_final.columns[21]: \"C-1\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['pdv', 'SKU', 'SKU_FINAL', 'ESTOQUE ATUAL', 'ESTOQUE EM TRANSITO',\n",
       "       'PEDIDO PENDENTE', 'Curva', 'CATEGORIA', 'DiasSemVenda',\n",
       "       'nextcycleprojection', 'secondtonextcycleprojection', 'Ciclo_x',\n",
       "       'Veiculo', 'Tipo de Promoção', 'Estratégia de Promoção',\n",
       "       'Tipo_mecanica', 'Promo Período Limitado?', 'EAM', 'Categoria',\n",
       "       'Cód. Combo', 'Código do Item', 'Descrição do Item',\n",
       "       'Chamada Promocional', 'Valor do Guia', 'Preço Promocionado',\n",
       "       '% de Desconto', 'RE compra por', 'RE Vende por', 'RE lucra  (R$)',\n",
       "       'MATCH', 'PDV', 'UF', 'DESCRIÇÃO PDV', 'ANALISTA', 'match', 'Ciclo_y',\n",
       "       'INICIO CICLO', 'FIM CICLO', 'DURAÇÃO', 'dias_ate_inicio', 'PDV_SKU',\n",
       "       'UFPRODUTO', 'DESCRICAO', 'C202411', 'C202412', 'C202413', 'C202414',\n",
       "       'C202415', 'C202416', 'C202417', 'C202501', 'C202502', 'C202503',\n",
       "       'C202504', 'C202505', 'C202506', 'C202507', 'C202508', 'C202509',\n",
       "       'C202510', 'C202511', 'C202512', 'C202513', 'PICO DE VENDAS 17CICLOS',\n",
       "       'Pico Vendas Ultimos 6 ciclos', 'CRESCIMENTO', 'MEDIANA DO HISTÓRICO',\n",
       "       'MEDIA DO HISTÓRICO', 'PV GINSENG'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final.drop(columns=df_final.columns[-21:-10], inplace=True)\n",
    "\n",
    "df_final.drop(columns=df_final.columns[-13:-11], inplace=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "# List all columns except the two\n",
    "cols_to_group_by = df_final.columns.difference(['DDV PREVISTO', 'COBERTURA ATUAL'])\n",
    "\n",
    "# Group and aggregate\n",
    "df_final_dedup = df_final\n",
    "   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final['Compra inteligente Próximo Ciclo']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final['DDV PREVISTO'] = df_final['DDV PREVISTO'].fillna(0.01)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup['DDV PREVISTO'] = np.where(\n",
    "#    df_final_dedup['DDV PREVISTO'] == 0,\n",
    "#    0.01,\n",
    "#    df_final_dedup['DDV PREVISTO']\n",
    "#)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup['DDV PREVISTO'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup['EST PROJE FINAL CICLO ATUAL'] = (df_final_dedup['Estoque Atual'] + df_final_dedup['Estoque em Transito']) - round(df_final_dedup['dias_ate_inicio'] * df_final_dedup['DDV PREVISTO'],0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup['EST PROJE FINAL CICLO ATUAL'] = np.where(df_final_dedup['EST PROJE FINAL CICLO ATUAL']<0,0,df_final_dedup['EST PROJE FINAL CICLO ATUAL'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup['VENDAS R$ PV GINSENG'] = df_final_dedup['PRECO DE VENDA'] * df_final_dedup['PV GINSENG']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup = df_final_dedup.rename(columns={'Ciclo_x':'Ciclo'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_final_dedup['SUGESTÃO ABTASTECIMENTO\t'] = ''\n",
    "df_final_dedup['VENDAS R$ ABASTECIMENTO'] = ''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup['RBV 202406'] = df_final_dedup['PRECO DE VENDA'] * df_final_dedup[ciclo_ano_passado] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup['COB PROJETADA'] = np.where(\n",
    "#    df_final_dedup['DDV PREVISTO'] != 0,\n",
    "#    (df_final_dedup['EST PROJE FINAL CICLO ATUAL'] + df_final_dedup['PV GINSENG']) / df_final_dedup['DDV PREVISTO'],\n",
    "#    999)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup.drop(columns=['dias_ate_inicio','SKU_FINAL','Projeção Próximo Ciclo + 1',\n",
    "#                             'CRESCIMENTO'],inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup['MARCA'] = df_final_dedup['MARCA'].str.replace('.csv','',regex=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup['COB PROJETADA'] = df_final_dedup['COB PROJETADA'].fillna(999)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_final_dedup.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [],
   "source": [
    "#marca_promo =  df_estoque['Arquivo_Origem'].iloc[0].replace('.csv','')\n",
    "#marca_promo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['pdv', 'SKU', 'SKU_FINAL', 'ESTOQUE ATUAL', 'ESTOQUE EM TRANSITO',\n",
       "       'PEDIDO PENDENTE', 'Curva', 'CATEGORIA', 'DiasSemVenda',\n",
       "       'nextcycleprojection', 'secondtonextcycleprojection', 'Ciclo_x',\n",
       "       'Veiculo', 'Tipo de Promoção', 'Estratégia de Promoção',\n",
       "       'Tipo_mecanica', 'Promo Período Limitado?', 'EAM', 'Categoria',\n",
       "       'Cód. Combo', 'Código do Item', 'Descrição do Item',\n",
       "       'Chamada Promocional', 'Valor do Guia', 'Preço Promocionado',\n",
       "       '% de Desconto', 'RE compra por', 'RE Vende por', 'RE lucra  (R$)',\n",
       "       'MATCH', 'PDV', 'UF', 'DESCRIÇÃO PDV', 'ANALISTA', 'match', 'Ciclo_y',\n",
       "       'INICIO CICLO', 'FIM CICLO', 'DURAÇÃO', 'dias_ate_inicio', 'PDV_SKU',\n",
       "       'UFPRODUTO', 'DESCRICAO', 'C202411', 'C202412', 'C202415', 'C202510',\n",
       "       'C202511', 'C202512', 'C202513', 'PICO DE VENDAS 17CICLOS',\n",
       "       'Pico Vendas Ultimos 6 ciclos', 'CRESCIMENTO', 'MEDIANA DO HISTÓRICO',\n",
       "       'MEDIA DO HISTÓRICO', 'PV GINSENG', 'SUGESTÃO ABTASTECIMENTO\\t',\n",
       "       'VENDAS R$ ABASTECIMENTO'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_final.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Passo 1: ordenar\n",
    "df_sorted = df_final.sort_values(by='% de Desconto', ascending=False)\n",
    "\n",
    "# Passo 2: obter até 3 chamadas promocionais por grupo\n",
    "promo_grouped = (\n",
    "    df_sorted.groupby(['SKU_FINAL', 'PDV'])['Chamada Promocional']\n",
    "    .apply(lambda x: x.dropna().unique()[:3])\n",
    "    .apply(pd.Series)\n",
    "    .rename(columns={0: 'MECÂNICA 1', 1: 'MECÂNICA 2', 2: 'MECÂNICA 3'})\n",
    "    .reset_index()\n",
    ")\n",
    "\n",
    "# Passo 3: base com maior % de desconto\n",
    "df_base = df_sorted.drop_duplicates(subset=['SKU_FINAL', 'PDV'], keep='first').reset_index(drop=True)\n",
    "\n",
    "# Passo 4: merge com chamadas pivotadas\n",
    "df_merged = df_base.merge(promo_grouped, on=['SKU_FINAL', 'PDV'], how='left')\n",
    "\n",
    "# Corrigir dicionário: agrupar e pegar o primeiro valor válido por (SKU_FINAL, PDV)\n",
    "# Passo 1: dicionário com Cód. Combo único por SKU_FINAL+PDV\n",
    "cod_combo_map = (\n",
    "    df_final\n",
    "    .dropna(subset=['Cód. Combo'])\n",
    "    .groupby(['SKU_FINAL', 'PDV'])['Cód. Combo']\n",
    "    .first()\n",
    "    .to_dict()\n",
    ")\n",
    "\n",
    "# Passo 2: gerar Series com os valores mapeados\n",
    "cod_combo_series = df_merged.set_index(['SKU_FINAL', 'pdv']).index.map(cod_combo_map)\n",
    "\n",
    "# Passo 3: substituir os valores diretamente\n",
    "df_merged['Cód. Combo'] = cod_combo_series.where(cod_combo_series.notna(), df_merged['Cód. Combo'])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PDV\n",
       "20986    196\n",
       "20991    196\n",
       "23712    196\n",
       "23711    196\n",
       "23704    196\n",
       "23703    196\n",
       "22541    196\n",
       "21495    196\n",
       "21383    196\n",
       "21375    196\n",
       "21278    196\n",
       "21001    196\n",
       "24269    196\n",
       "23813    196\n",
       "24255    196\n",
       "24257    196\n",
       "24293    196\n",
       "20970    196\n",
       "20969    196\n",
       "20968    196\n",
       "20999    196\n",
       "21000    196\n",
       "20996    196\n",
       "20995    196\n",
       "20997    196\n",
       "20998    196\n",
       "20989    196\n",
       "20994    196\n",
       "20992    196\n",
       "20993    196\n",
       "20988    196\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_merged.PDV.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Columns to bring up front\n",
    "priority_cols = [\n",
    "    'PDV_SKU',\t'SKU',\t'MARCA','INICIO CICLO',\n",
    "    'FIM CICLO',\t'DURAÇÃO','dias_ate_inicio',\t\n",
    "    'UFPRODUTO',\t'Item Desativado',\t'Data Prevista Regularização',\n",
    "    'ANALISTA',\t'UF',\t'PDV',\t'DESCRIÇÃO PDV',\t'Classe',\n",
    "    'Descrição','MECÂNICA 1',\n",
    "       'MECÂNICA 2', 'MECÂNICA 3','Estoque Atual',\t'COBERTURA ATUAL',\n",
    "    'Estoque em Transito',\t'Pedido Pendente',\t'PICO DE VENDAS 2024','Pico Vendas Ultimos 6 ciclos',\n",
    "    'C-4',\t'C-3',\t'C-2',\t'C-1',\t'Histórico de Vendas do Ciclo Atual',\n",
    "    'Dias sem venda'\n",
    "]\n",
    "\n",
    "# All remaining columns\n",
    "other_cols = [col for col in df_merged.columns if col not in priority_cols]\n",
    "\n",
    "# Reorder\n",
    "df_merged = df_merged[priority_cols + other_cols]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged['INICIO CICLO'] = pd.to_datetime(df_merged['INICIO CICLO'], dayfirst=True).dt.strftime('%d/%m/%Y')\n",
    "\n",
    "df_merged['FIM CICLO'] = pd.to_datetime(df_merged['FIM CICLO'], dayfirst=True).dt.strftime('%d/%m/%Y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['pdv', 'SKU', 'SKU_FINAL', 'ESTOQUE ATUAL', 'ESTOQUE EM TRANSITO',\n",
       "       'PEDIDO PENDENTE', 'Curva', 'CATEGORIA', 'DiasSemVenda',\n",
       "       'nextcycleprojection', 'secondtonextcycleprojection', 'Ciclo_x',\n",
       "       'Veiculo', 'Tipo de Promoção', 'Estratégia de Promoção',\n",
       "       'Tipo_mecanica', 'Promo Período Limitado?', 'EAM', 'Categoria',\n",
       "       'Cód. Combo', 'Código do Item', 'Descrição do Item',\n",
       "       'Chamada Promocional', 'Valor do Guia', 'Preço Promocionado',\n",
       "       '% de Desconto', 'RE compra por', 'RE Vende por', 'RE lucra  (R$)',\n",
       "       'MATCH', 'PDV', 'UF', 'DESCRIÇÃO PDV', 'ANALISTA', 'match', 'Ciclo_y',\n",
       "       'INICIO CICLO', 'FIM CICLO', 'DURAÇÃO', 'dias_ate_inicio', 'PDV_SKU',\n",
       "       'UFPRODUTO', 'DESCRICAO', 'C202411', 'C202412', 'C202415', 'C202510',\n",
       "       'C202511', 'C202512', 'C202513', 'PICO DE VENDAS 17CICLOS',\n",
       "       'Pico Vendas Ultimos 6 ciclos', 'CRESCIMENTO', 'MEDIANA DO HISTÓRICO',\n",
       "       'MEDIA DO HISTÓRICO', 'PV GINSENG', 'SUGESTÃO ABTASTECIMENTO\\t',\n",
       "       'VENDAS R$ ABASTECIMENTO', 'MECÂNICA 1', 'MECÂNICA 2', 'MECÂNICA 3'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_merged.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged = df_merged.loc[:, ~df_merged.columns.str.endswith('_y')]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged.columns = df_merged.columns.str.replace('_x$', '', regex=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged['DESCRICAO'] = df_merged['Descrição do Item']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged['SKU'] = np.where(df_merged['SKU'].isna(),df_merged['SKU_FINAL'],df_merged['SKU'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged = df_merged.drop(columns=['Veiculo',\t'Tipo de Promoção',\t'Estratégia de Promoção','Tipo_mecanica'\n",
    "                                    ,'Chamada Promocional','MATCH','match','Descrição do Item','CRESCIMENTO',\n",
    "                                    'Cód. Combo'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged = df_merged.drop(columns=['Código do Item','PDV','RE compra por',\t'RE Vende por',\t'RE lucra  (R$)','INICIO CICLO',\n",
    "                                    'FIM CICLO','Ciclo','CATEGORIA','ANALISTA','dias_ate_inicio','PDV_SKU','UFPRODUTO',\n",
    "                                    'VENDAS R$ ABASTECIMENTO','DURAÇÃO','MEDIANA DO HISTÓRICO','DURAÇÃO'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged = df_merged.rename(columns={'nextcycleprojection':'PROJEÇÃO PROX CICLO'\t,'secondtonextcycleprojection':'PROJEÇÃO PROX CICLO +1'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged.columns = df_merged.columns.str.upper()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_merged = df_merged[['UF','PDV','DESCRIÇÃO PDV','SKU','DESCRICAO','EAM','CATEGORIA','CURVA','ESTOQUE ATUAL','ESTOQUE EM TRANSITO','PEDIDO PENDENTE','DIASSEMVENDA','PROJEÇÃO PROX CICLO','PROJEÇÃO PROX CICLO +1','PROMO PERÍODO LIMITADO?','VALOR DO GUIA','PREÇO PROMOCIONADO','% DE DESCONTO','PICO DE VENDAS 17CICLOS','PICO VENDAS ULTIMOS 6 CICLOS','MEDIA DO HISTÓRICO']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged['MEDIA DO HISTÓRICO'] = round(df_merged['MEDIA DO HISTÓRICO'],0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged[df_merged.columns[19:26]] = df_merged[df_merged.columns[19:26]].fillna(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Colunas que devem estar na frente\n",
    "colunas_inicio = [\n",
    "    'UF', 'PDV', 'DESCRIÇÃO PDV', 'SKU', 'DESCRICAO', 'EAM', 'CATEGORIA', 'CURVA',\n",
    "    'ESTOQUE ATUAL', 'ESTOQUE EM TRANSITO', 'PEDIDO PENDENTE', 'DIASSEMVENDA',\n",
    "    'PROJEÇÃO PROX CICLO', 'PROJEÇÃO PROX CICLO +1', 'PROMO PERÍODO LIMITADO?',\n",
    "    'VALOR DO GUIA', 'PREÇO PROMOCIONADO', '% DE DESCONTO',\n",
    "    'PICO DE VENDAS 17CICLOS', 'PICO VENDAS ULTIMOS 6 CICLOS', 'MEDIA DO HISTÓRICO'\n",
    "]\n",
    "\n",
    "# Colunas que devem estar no fim\n",
    "colunas_fim = [\n",
    "    'PV GINSENG', 'SUGESTÃO ABTASTECIMENTO\\t'\n",
    "]\n",
    "\n",
    "# Todas as outras colunas (não estão nem no início nem no fim)\n",
    "colunas_meio = [col for col in df_merged.columns if col not in colunas_inicio + colunas_fim]\n",
    "\n",
    "# Reordena o DataFrame\n",
    "df_merged = df_merged[colunas_inicio + colunas_meio + colunas_fim]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_merged = df_merged.drop_duplicates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2025-09-03'"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hoje=datetime.today().strftime('%Y-%m-%d')\n",
    "hoje"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "from openpyxl import load_workbook\n",
    "from openpyxl.styles import PatternFill, Font\n",
    "\n",
    "\n",
    "# Export to Excel\n",
    "output_file = f'C:\\\\Users\\\\joao.herculano\\\\Documents\\\\EUD_promoção_{ciclo_mais2}_{hoje}.xlsx'\n",
    "with pd.ExcelWriter(output_file, engine='openpyxl') as writer:\n",
    "    df_merged.to_excel(writer, index=False, sheet_name='Sheet1')\n",
    "\n",
    "# Apply styles\n",
    "wb = load_workbook(output_file)\n",
    "ws = wb['Sheet1']\n",
    "\n",
    "# Style header\n",
    "header_fill = PatternFill(start_color='ADD8E6', end_color='ADD8E6', fill_type='solid')  # Light Blue\n",
    "header_font = Font(color='FFFFFF', bold=True)  # White & Bold\n",
    "\n",
    "for cell in ws[1]:\n",
    "    cell.fill = header_fill\n",
    "    cell.font = header_font\n",
    "\n",
    "# Style rows: gray/white alternating\n",
    "gray_fill = PatternFill(start_color='DDDDDD', end_color='DDDDDD', fill_type='solid')  # Light gray\n",
    "\n",
    "for i, row in enumerate(ws.iter_rows(min_row=2, max_row=ws.max_row), start=2):\n",
    "    if i % 2 == 0:\n",
    "        for cell in row:\n",
    "            cell.fill = gray_fill\n",
    "\n",
    "# Save styled workbook\n",
    "wb.save(output_file)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "coisas q saem\n",
    "\n",
    "Lançamento\n",
    "Subcategoria\n",
    "Projeção Próximo Ciclo \n",
    "Promoção Próximo Ciclo\n",
    "Compra inteligente semanal/Sugestão de compra\n",
    "Compra inteligente Próximo Ciclo\n",
    "Planograma\n",
    "Carteira Bloqueada Para Novos Pedidos\n",
    "Quantidade por caixa\n",
    "Preço Sell In\n",
    "Quantidade\n",
    "Item analisado\n",
    "Tipo Preço\n",
    "\n",
    ">>>>>>>>>>>>>NAO ESTÁ PEGANDO O MERGE COM O DF_ESTOQUE\n",
    "\n",
    "\n",
    "CRIAR PROJEÇÃO DE VENDA DO CICLO ATUAL\n",
    "Compra inteligente Próximo Ciclo + 1 >>>>>>> RENAME PRA NOROMAL"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "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": 2
}
