1482 lines
47 KiB
Plaintext
1482 lines
47 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 1,
|
||
"id": "6ad35669",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import pandas as pd\n",
|
||
"import numpy as np \n",
|
||
"import glob\n",
|
||
"import os "
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 2,
|
||
"id": "9fcdc77a",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"calendario = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\BASE DE DADOS LANÇAMENTO\\BOT\\CICLO 9\\CALENDARIO_CICLO\\Ciclo_Expandido_com_Datas.xlsx\")\n",
|
||
"\n",
|
||
"calendario['Date'] = pd.to_datetime(calendario['Date'])\n",
|
||
"\n",
|
||
"# Get today (normalized to midnight)\n",
|
||
"today = pd.Timestamp(\"today\").normalize()\n",
|
||
"\n",
|
||
"calendario['NUM_CICLO'] = calendario['Ciclo'].str[-2:].astype(int)\n",
|
||
"\n",
|
||
"calendario['ANO_CICLO'] = calendario['Ciclo'].str[0:5]\n",
|
||
"\n",
|
||
"calendario = calendario[calendario['MARCA'] == \"EUDORA\"]\n",
|
||
"\n",
|
||
"calendario['CICLOMAIS2'] = calendario['ANO_CICLO'].astype(str) + (calendario['NUM_CICLO'].astype(int) + 3).astype(str).str.zfill(2) #<<< MUDAR O \"4\" (CICLO ATUAL + 4 PARA ACHAR O CICLO DA SUGESTÃO) EX: C202505 -> C202509\n",
|
||
"ciclo_mais2 = calendario[calendario['Date'].dt.normalize() == today]['CICLOMAIS2'].iloc[0]\n",
|
||
"\n",
|
||
"# Filter rows where date matches today\n",
|
||
"filtered_calendario = calendario[calendario['Ciclo'] == ciclo_mais2][:1]\n",
|
||
"\n",
|
||
"filtered_calendario['dias_ate_inicio'] = filtered_calendario['INICIO CICLO'].iloc[0] - today\n",
|
||
"\n",
|
||
"filtered_calendario['dias_ate_inicio'] = filtered_calendario['dias_ate_inicio'].dt.days.astype(int)\n",
|
||
"\n",
|
||
"filtered_calendario['match'] = 1\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 3,
|
||
"id": "bbec229d",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/html": [
|
||
"<div>\n",
|
||
"<style scoped>\n",
|
||
" .dataframe tbody tr th:only-of-type {\n",
|
||
" vertical-align: middle;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe tbody tr th {\n",
|
||
" vertical-align: top;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe thead th {\n",
|
||
" text-align: right;\n",
|
||
" }\n",
|
||
"</style>\n",
|
||
"<table border=\"1\" class=\"dataframe\">\n",
|
||
" <thead>\n",
|
||
" <tr style=\"text-align: right;\">\n",
|
||
" <th></th>\n",
|
||
" <th>Ciclo</th>\n",
|
||
" <th>INICIO CICLO</th>\n",
|
||
" <th>FIM CICLO</th>\n",
|
||
" <th>DURAÇÃO</th>\n",
|
||
" <th>MARCA</th>\n",
|
||
" <th>Date</th>\n",
|
||
" <th>NUM_CICLO</th>\n",
|
||
" <th>ANO_CICLO</th>\n",
|
||
" <th>CICLOMAIS2</th>\n",
|
||
" <th>dias_ate_inicio</th>\n",
|
||
" <th>match</th>\n",
|
||
" </tr>\n",
|
||
" </thead>\n",
|
||
" <tbody>\n",
|
||
" <tr>\n",
|
||
" <th>2262</th>\n",
|
||
" <td>C202511</td>\n",
|
||
" <td>2025-07-16</td>\n",
|
||
" <td>2025-08-05</td>\n",
|
||
" <td>21</td>\n",
|
||
" <td>EUDORA</td>\n",
|
||
" <td>2025-07-16</td>\n",
|
||
" <td>11</td>\n",
|
||
" <td>C2025</td>\n",
|
||
" <td>C202514</td>\n",
|
||
" <td>54</td>\n",
|
||
" <td>1</td>\n",
|
||
" </tr>\n",
|
||
" </tbody>\n",
|
||
"</table>\n",
|
||
"</div>"
|
||
],
|
||
"text/plain": [
|
||
" Ciclo INICIO CICLO FIM CICLO DURAÇÃO MARCA Date NUM_CICLO \\\n",
|
||
"2262 C202511 2025-07-16 2025-08-05 21 EUDORA 2025-07-16 11 \n",
|
||
"\n",
|
||
" ANO_CICLO CICLOMAIS2 dias_ate_inicio match \n",
|
||
"2262 C2025 C202514 54 1 "
|
||
]
|
||
},
|
||
"execution_count": 3,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"filtered_calendario"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 4,
|
||
"id": "61ffc777",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_similares = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\EUDORA\\C11\\arquivos usados na sugestão\\SIMILARES\\PRODUTOS SIMILARES - EUD.xlsx\")\n",
|
||
"\n",
|
||
"df_similares = pd.merge(left=df_similares,right=calendario[['Ciclo','INICIO CICLO','FIM CICLO','DURAÇÃO']], how= 'left', left_on = 'CICLO SIMILAR',right_on = 'Ciclo' )\n",
|
||
"\n",
|
||
"df_similares = df_similares.drop(columns=['Ciclo'])\n",
|
||
"\n",
|
||
"df_similares = df_similares.rename(columns={'INICIO CICLO':'INICIO CICLO SIMILAR','FIM CICLO':'FIM CICLO SIMILAR','DURAÇÃO':'DURAÇÃO CICLO SIMILAR'})\n",
|
||
"df_similares.drop_duplicates(inplace=True)\n",
|
||
"\n",
|
||
"df_similares['MATCH'] = 1\n",
|
||
"\n",
|
||
"df_similares = df_similares.drop(columns=['INICIO DO CICLO',\n",
|
||
" 'FIM DO CICLO', 'DURAÇÃO CICLO','INICIO CICLO SIMILAR','FIM CICLO SIMILAR','DURAÇÃO CICLO SIMILAR'])"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 5,
|
||
"id": "99ea95e6",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"Index(['PRODUTO LANÇAMENTO', 'DESCRIÇÃO DO LANÇAMENTO', 'PRODUTO SIMILAR',\n",
|
||
" 'DESCRIÇÃO SIMILAR', 'CICLO SIMILAR', 'FOCO', 'IAF', 'CATEGORIA',\n",
|
||
" 'MARCA', '% CONSUMIDOR', 'MECANICA CONSUMIDOR', '% REVENDEDOR',\n",
|
||
" 'MECANICA REVENDEDOR', 'TIPO DE PRODUTO', 'MATCH'],\n",
|
||
" dtype='object')"
|
||
]
|
||
},
|
||
"execution_count": 5,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_similares.columns"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 6,
|
||
"id": "fe922f62",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_tabela = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\EUDORA\\C11\\arquivos usados na sugestão\\TABELA DE PEDIDO\\Pedidos Semanais Especiais - GKD - 202511.xlsx\")\n",
|
||
"\n",
|
||
"df_tabela = df_tabela[df_tabela['Região'] == 'NNE'] \n",
|
||
"\n",
|
||
"df_tabela = df_tabela[(df_tabela['Canal'] != 'Ecomm') | (df_tabela['Canal'] != 'Ecomm | VD') | (df_tabela['Canal'] != 'Ecomm | Loja')] \n",
|
||
"\n",
|
||
"df_tabela['Canal'] = np.where((df_tabela['Canal'] == \"Loja\") | (df_tabela['Canal'] == \"Todos\") | (df_tabela['Canal'] == \"Loja | VD\"),\"TODOS\",\"VD\")\n",
|
||
"\n",
|
||
"#df_tabela = df_tabela[df_tabela['Tipo de promoção'].str.contains('Lançamentos', na=False)]"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 7,
|
||
"id": "a3a045d9",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_pdv = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\EUDORA\\C11\\arquivos usados na sugestão\\PDVS EUD\\PDV_ATT.xlsx\")\n",
|
||
"\n",
|
||
"df_pdv_origi = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\EUDORA\\C11\\arquivos usados na sugestão\\PDVS EUD\\PDV_ATT.xlsx\")\n",
|
||
"\n",
|
||
"df_pdv = df_pdv.rename(columns={'DESCRIÇÃO':'DESCRIÇÃO PDV'})\n",
|
||
"\n",
|
||
"df_pdv = df_pdv.drop(columns=['REGIÃO', 'ESTADO','CIDADE','GESTÃO','MARCA'])\n",
|
||
"\n",
|
||
"df_pdv['PDV'] = df_pdv['PDV DESC'].str.split(\"-\").str[0].str.strip()\n",
|
||
"\n",
|
||
"df_pdv['UF'] = np.where(df_pdv['UF'] == 'VDC','BA',df_pdv['UF'])\n",
|
||
"\n",
|
||
"#ignorando a PDV que ainda não está online\n",
|
||
"df_pdv = df_pdv[df_pdv['DESCRIÇÃO PDV'] != '23813-COMERCIO-HIB VALENTE']\n",
|
||
"\n",
|
||
"df_pdv = df_pdv[df_pdv['status'] != \"INATIVO\"]\n",
|
||
"\n",
|
||
"df_pdv = df_pdv[df_pdv['status'] != \"MATRIZ\"]\n",
|
||
"\n",
|
||
"df_pdv = df_pdv[df_pdv['SUPERVISOR'] != 'Inativa']\n",
|
||
"\n",
|
||
"df_pdv['MATCH'] = 1"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 8,
|
||
"id": "849d5297",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"Index(['PDV', 'CANAL', 'DESCRIÇÃO PDV', 'PDV DESC', 'UF', 'ANALISTA',\n",
|
||
" 'SUPERVISOR', 'status', 'MATCH'],\n",
|
||
" dtype='object')"
|
||
]
|
||
},
|
||
"execution_count": 8,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_pdv.columns"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 9,
|
||
"id": "df04a501",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_similares = pd.merge(left=df_similares,right=df_pdv,right_on=['MATCH'],left_on=['MATCH'],how='inner')\n",
|
||
"\n",
|
||
"df_similares = df_similares.drop_duplicates()"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 10,
|
||
"id": "0da911af",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stderr",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"C:\\Users\\joao.herculano\\AppData\\Local\\Temp\\ipykernel_61796\\3284054138.py:10: DtypeWarning: Columns (7) have mixed types. Specify dtype option on import or set low_memory=False.\n",
|
||
" df_draft = pd.concat([pd.read_csv(file) for file in csv_files], ignore_index=True)\n"
|
||
]
|
||
},
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"(111818, 47)"
|
||
]
|
||
},
|
||
"execution_count": 10,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"# Caminho onde estão as subpastas com os arquivos CSV\n",
|
||
"\n",
|
||
"# Set the path to the folder containing CSV files\n",
|
||
"folder_path = r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\EUDORA\\C11\\arquivos usados na sugestão\\DRAFT\" # arquivo dos drafts\n",
|
||
"\n",
|
||
"# Pattern to match all CSV files\n",
|
||
"csv_files = glob.glob(os.path.join(folder_path, '*.csv'))\n",
|
||
"\n",
|
||
"# Read and concat all CSVs\n",
|
||
"df_draft = pd.concat([pd.read_csv(file) for file in csv_files], ignore_index=True)\n",
|
||
"\n",
|
||
"df_draft['match'] = 1 \n",
|
||
"\n",
|
||
"df_draft.shape\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 11,
|
||
"id": "0c8c7493",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_draft = df_draft.drop(columns=['Categoria'])"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 12,
|
||
"id": "91298cde",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"Index(['Histórico de Vendas do Ciclo 202407',\n",
|
||
" 'Histórico de Vendas do Ciclo 202408',\n",
|
||
" 'Histórico de Vendas do Ciclo 202409',\n",
|
||
" 'Histórico de Vendas do Ciclo 202410',\n",
|
||
" 'Histórico de Vendas do Ciclo 202411',\n",
|
||
" 'Histórico de Vendas do Ciclo 202412',\n",
|
||
" 'Histórico de Vendas do Ciclo 202413',\n",
|
||
" 'Histórico de Vendas do Ciclo 202414',\n",
|
||
" 'Histórico de Vendas do Ciclo 202415',\n",
|
||
" 'Histórico de Vendas do Ciclo 202416',\n",
|
||
" 'Histórico de Vendas do Ciclo 202417',\n",
|
||
" 'Histórico de Vendas do Ciclo 202501',\n",
|
||
" 'Histórico de Vendas do Ciclo 202502',\n",
|
||
" 'Histórico de Vendas do Ciclo 202503',\n",
|
||
" 'Histórico de Vendas do Ciclo 202504',\n",
|
||
" 'Histórico de Vendas do Ciclo 202505',\n",
|
||
" 'Histórico de Vendas do Ciclo 202506',\n",
|
||
" 'Histórico de Vendas do Ciclo Atual'],\n",
|
||
" dtype='object')"
|
||
]
|
||
},
|
||
"execution_count": 12,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_draft.columns[7:25]"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 13,
|
||
"id": "34e179cb",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stderr",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"C:\\Users\\joao.herculano\\AppData\\Local\\Temp\\ipykernel_61796\\1463083786.py:24: DeprecationWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.\n",
|
||
" crescimento_por_pdv = df_draft.groupby('PDV').apply(calcular_crescimento)\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"# Define as colunas mensais\n",
|
||
"colunas_mensais = df_draft.columns[7:25]\n",
|
||
"\n",
|
||
"# Agrupa por PDV e calcula crescimento médio por PDV\n",
|
||
"def calcular_crescimento(grupo):\n",
|
||
" soma_mensal = grupo[colunas_mensais].sum() # soma por mês\n",
|
||
" variacao_mensal = soma_mensal.pct_change().dropna() # variação percentual mês a mês\n",
|
||
" variacao_mensal = variacao_mensal[np.isfinite(variacao_mensal)]\n",
|
||
"\n",
|
||
" if len(variacao_mensal) == 0:\n",
|
||
" return pd.Series({'CRESCIMENTO': np.nan})\n",
|
||
"\n",
|
||
" media = variacao_mensal.mean()\n",
|
||
" desvio = variacao_mensal.std()\n",
|
||
"\n",
|
||
" limite_sup = media + 2 * desvio\n",
|
||
" limite_inf = media - 2 * desvio\n",
|
||
"\n",
|
||
" variacoes_filtradas = variacao_mensal[variacao_mensal.between(limite_inf, limite_sup)]\n",
|
||
" crescimento = round(variacoes_filtradas.mean(), 4)\n",
|
||
" return pd.Series({'CRESCIMENTO': crescimento})\n",
|
||
"\n",
|
||
"# Aplica a função por PDV\n",
|
||
"crescimento_por_pdv = df_draft.groupby('PDV').apply(calcular_crescimento)\n",
|
||
"\n",
|
||
"# Merge do resultado de volta no dataframe original\n",
|
||
"df_draft = df_draft.merge(crescimento_por_pdv, on='PDV', how='left')\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 14,
|
||
"id": "4bc8c2b4",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_similares['PDV'] = df_similares['PDV'].astype('Int64')\n",
|
||
"\n",
|
||
"df_final = pd.merge(left=df_similares,right=df_draft,right_on=['PDV', 'SKU'],left_on=['PDV','PRODUTO SIMILAR'],how='left')"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 15,
|
||
"id": "c1451562",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"(2455, 14)"
|
||
]
|
||
},
|
||
"execution_count": 15,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_venda_diaria = pd.read_excel(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\EUDORA\\C11\\arquivos usados na sugestão\\VENDAS_DIARIAS\\FormFiltroConsultaVendaSintetica_23_05_2025_09_22_15.xls\")\n",
|
||
"\n",
|
||
"df_venda_diaria.shape"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 16,
|
||
"id": "882e68aa",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"Index(['Unidade de Negócio', 'Ano', 'Mês', 'Dia', 'Código do Produto',\n",
|
||
" 'Descrição do Produto', 'Quantidade', 'Valor Bruto', 'Valor Desconto',\n",
|
||
" 'Valor Líquido', 'Valor Vale Troca', 'Líquido - Troca', 'Estoque Atual',\n",
|
||
" 'Estoque Mínimo'],\n",
|
||
" dtype='object')"
|
||
]
|
||
},
|
||
"execution_count": 16,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_venda_diaria.columns"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 17,
|
||
"id": "c7ddaf20",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"(2455, 16)"
|
||
]
|
||
},
|
||
"execution_count": 17,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_venda_diaria['PDV'] = df_venda_diaria['Unidade de Negócio'].str.split(\"-\").str[0].str.strip()\n",
|
||
"\n",
|
||
"df_venda_diaria['Dia'] = pd.to_datetime(df_venda_diaria['Dia'], format='%d/%m/%Y')\n",
|
||
"\n",
|
||
"df_venda_diaria = pd.merge(left=df_venda_diaria,right=calendario[['Ciclo','Date']],left_on='Dia',right_on='Date',how='inner')\n",
|
||
"\n",
|
||
"df_venda_diaria = df_venda_diaria.drop(columns='Date')\n",
|
||
"\n",
|
||
"df_venda_diaria.shape"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 18,
|
||
"id": "7119556a",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"(2455, 17)"
|
||
]
|
||
},
|
||
"execution_count": 18,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"# 'Dia' já está em formato datetime, então renomeamos para 'Data' diretamente\n",
|
||
"# ou apenas usamos 'Dia' como referência de data\n",
|
||
"\n",
|
||
"# Ordena o DataFrame para garantir que a cumulativa funcione corretamente\n",
|
||
"df_venda_diaria = df_venda_diaria.sort_values(by=['Unidade de Negócio', 'Código do Produto', 'Dia'])\n",
|
||
"\n",
|
||
"# Calcula a quantidade acumulada até o dia para cada grupo\n",
|
||
"df_venda_diaria['Quantidade Acumulada'] = (\n",
|
||
" df_venda_diaria\n",
|
||
" .groupby(['Unidade de Negócio', 'Código do Produto'])['Quantidade']\n",
|
||
" .cumsum()\n",
|
||
") # acumulado por grupo até a data da linha\n",
|
||
"\n",
|
||
"df_venda_diaria.shape"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 19,
|
||
"id": "c707a1b6",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/html": [
|
||
"<div>\n",
|
||
"<style scoped>\n",
|
||
" .dataframe tbody tr th:only-of-type {\n",
|
||
" vertical-align: middle;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe tbody tr th {\n",
|
||
" vertical-align: top;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe thead th {\n",
|
||
" text-align: right;\n",
|
||
" }\n",
|
||
"</style>\n",
|
||
"<table border=\"1\" class=\"dataframe\">\n",
|
||
" <thead>\n",
|
||
" <tr style=\"text-align: right;\">\n",
|
||
" <th></th>\n",
|
||
" <th>PDV</th>\n",
|
||
" <th>Código do Produto</th>\n",
|
||
" <th>Ciclo</th>\n",
|
||
" <th>Quantidade Acumulada</th>\n",
|
||
" </tr>\n",
|
||
" </thead>\n",
|
||
" <tbody>\n",
|
||
" <tr>\n",
|
||
" <th>0</th>\n",
|
||
" <td>20968</td>\n",
|
||
" <td>50112</td>\n",
|
||
" <td>C202310</td>\n",
|
||
" <td>44</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>1</th>\n",
|
||
" <td>20968</td>\n",
|
||
" <td>50112</td>\n",
|
||
" <td>C202311</td>\n",
|
||
" <td>60</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>2</th>\n",
|
||
" <td>20968</td>\n",
|
||
" <td>50112</td>\n",
|
||
" <td>C202313</td>\n",
|
||
" <td>70</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>3</th>\n",
|
||
" <td>20968</td>\n",
|
||
" <td>50112</td>\n",
|
||
" <td>C202314</td>\n",
|
||
" <td>73</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>4</th>\n",
|
||
" <td>20968</td>\n",
|
||
" <td>50112</td>\n",
|
||
" <td>C202315</td>\n",
|
||
" <td>75</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>...</th>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>528</th>\n",
|
||
" <td>22541</td>\n",
|
||
" <td>52699</td>\n",
|
||
" <td>C202409</td>\n",
|
||
" <td>10</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>529</th>\n",
|
||
" <td>22541</td>\n",
|
||
" <td>52699</td>\n",
|
||
" <td>C202410</td>\n",
|
||
" <td>11</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>530</th>\n",
|
||
" <td>22541</td>\n",
|
||
" <td>52699</td>\n",
|
||
" <td>C202411</td>\n",
|
||
" <td>13</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>531</th>\n",
|
||
" <td>22541</td>\n",
|
||
" <td>56572</td>\n",
|
||
" <td>C202411</td>\n",
|
||
" <td>38</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>532</th>\n",
|
||
" <td>22541</td>\n",
|
||
" <td>57390</td>\n",
|
||
" <td>C202411</td>\n",
|
||
" <td>22</td>\n",
|
||
" </tr>\n",
|
||
" </tbody>\n",
|
||
"</table>\n",
|
||
"<p>533 rows × 4 columns</p>\n",
|
||
"</div>"
|
||
],
|
||
"text/plain": [
|
||
" PDV Código do Produto Ciclo Quantidade Acumulada\n",
|
||
"0 20968 50112 C202310 44\n",
|
||
"1 20968 50112 C202311 60\n",
|
||
"2 20968 50112 C202313 70\n",
|
||
"3 20968 50112 C202314 73\n",
|
||
"4 20968 50112 C202315 75\n",
|
||
".. ... ... ... ...\n",
|
||
"528 22541 52699 C202409 10\n",
|
||
"529 22541 52699 C202410 11\n",
|
||
"530 22541 52699 C202411 13\n",
|
||
"531 22541 56572 C202411 38\n",
|
||
"532 22541 57390 C202411 22\n",
|
||
"\n",
|
||
"[533 rows x 4 columns]"
|
||
]
|
||
},
|
||
"execution_count": 19,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_venda_diaria = df_venda_diaria.drop_duplicates()\n",
|
||
"\n",
|
||
"df_venda_agrupado = df_venda_diaria.groupby(['PDV', 'Código do Produto','Ciclo'])['Quantidade Acumulada'].max().reset_index()\n",
|
||
"df_venda_agrupado"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 20,
|
||
"id": "dc452c72",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"(170, 75)"
|
||
]
|
||
},
|
||
"execution_count": 20,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_final = pd.merge(left=df_final, right=filtered_calendario[['Ciclo','INICIO CICLO','FIM CICLO','DURAÇÃO','match','dias_ate_inicio']], right_on='match',left_on='MATCH',how='left')\n",
|
||
"df_final.shape"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 21,
|
||
"id": "c260e0e3",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"#df_final = df_final.drop(columns=['PDV DESC','status','SKU','Descrição','Lançamento','Item analisado','Planograma','Quantidade por caixa'])"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 22,
|
||
"id": "8a05450c",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final = pd.merge(left=df_final, right=calendario[['Ciclo','INICIO CICLO','FIM CICLO','DURAÇÃO']], right_on='Ciclo',left_on='CICLO SIMILAR',how='left')\n",
|
||
"df_final.shape\n",
|
||
"\n",
|
||
"df_final = df_final.drop_duplicates()"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 23,
|
||
"id": "cc65edab",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"\n",
|
||
"df_venda_agrupado = df_venda_agrupado.rename(columns={'Quantidade Acumulada':'Vendas Ciclo Lançamento'})"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 24,
|
||
"id": "c5cd5f42",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final['PRODUTO LANÇAMENTO'] = df_final['PRODUTO LANÇAMENTO'].astype('Int64')\n",
|
||
"\n",
|
||
"df_venda_agrupado['PDV'] = df_venda_agrupado['PDV'].astype('Int64')\n",
|
||
"\n",
|
||
"df_final = pd.merge(left=df_final, right = df_venda_agrupado, right_on=['Ciclo','Código do Produto','PDV'],left_on=['CICLO SIMILAR','PRODUTO SIMILAR','PDV'],how='left')\n",
|
||
"\n",
|
||
"df_final = df_final.drop_duplicates()"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 25,
|
||
"id": "69c88d20",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"np.int64(17)"
|
||
]
|
||
},
|
||
"execution_count": 25,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_final['PDV'].value_counts().min()"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 26,
|
||
"id": "f5206f50",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"Index(['Histórico de Vendas do Ciclo 202407',\n",
|
||
" 'Histórico de Vendas do Ciclo 202408',\n",
|
||
" 'Histórico de Vendas do Ciclo 202409',\n",
|
||
" 'Histórico de Vendas do Ciclo 202410',\n",
|
||
" 'Histórico de Vendas do Ciclo 202411',\n",
|
||
" 'Histórico de Vendas do Ciclo 202412',\n",
|
||
" 'Histórico de Vendas do Ciclo 202413',\n",
|
||
" 'Histórico de Vendas do Ciclo 202414',\n",
|
||
" 'Histórico de Vendas do Ciclo 202415',\n",
|
||
" 'Histórico de Vendas do Ciclo 202416',\n",
|
||
" 'Histórico de Vendas do Ciclo 202417',\n",
|
||
" 'Histórico de Vendas do Ciclo 202501',\n",
|
||
" 'Histórico de Vendas do Ciclo 202502',\n",
|
||
" 'Histórico de Vendas do Ciclo 202503',\n",
|
||
" 'Histórico de Vendas do Ciclo 202504',\n",
|
||
" 'Histórico de Vendas do Ciclo 202505',\n",
|
||
" 'Histórico de Vendas do Ciclo 202506'],\n",
|
||
" dtype='object')"
|
||
]
|
||
},
|
||
"execution_count": 26,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_final.columns[29:46]"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 27,
|
||
"id": "0a1bb832",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"np.float64(0.2176)"
|
||
]
|
||
},
|
||
"execution_count": 27,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"# Suponha que os meses estão nas colunas 10 a 26 (17 colunas = 17 meses)\n",
|
||
"colunas_mensais = df_final.columns[29:46]\n",
|
||
"\n",
|
||
"# Passo 1: Soma todas as linhas (itens) por mês → resultado: total por mês\n",
|
||
"soma_mensal = df_final[colunas_mensais].sum()\n",
|
||
"\n",
|
||
"# Passo 2: Calcula a variação percentual de um mês para o outro\n",
|
||
"variacao_mensal = soma_mensal.pct_change()\n",
|
||
"variacao_mensal = variacao_mensal.dropna()\n",
|
||
"\n",
|
||
"variacao_mensal = variacao_mensal[np.isfinite(variacao_mensal)]\n",
|
||
"\n",
|
||
"# Passo 3: Calcula a média da variação (ignorando o primeiro NaN)\n",
|
||
"media_variacao = variacao_mensal[1:].mean()\n",
|
||
"\n",
|
||
"# Calcula média e desvio padrão\n",
|
||
"media = variacao_mensal.mean()\n",
|
||
"desvio = variacao_mensal.std()\n",
|
||
"\n",
|
||
"# Define limite (ex: 2 desvios padrão)\n",
|
||
"limite_superior = media + 2 * desvio\n",
|
||
"limite_inferior = media - 2 * desvio\n",
|
||
"\n",
|
||
"# Filtra dados dentro do limite\n",
|
||
"filtro = variacao_mensal.between(limite_inferior, limite_superior)\n",
|
||
"df_filtrado = variacao_mensal[filtro]\n",
|
||
"CRESCIMENTO = round(df_filtrado.mean(),4)\n",
|
||
"\n",
|
||
"df_final['CRESCIMENTO_GERAL'] = CRESCIMENTO\n",
|
||
"\n",
|
||
"CRESCIMENTO\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 28,
|
||
"id": "a9647c32",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final = df_final.drop(columns='Ciclo_y')\n",
|
||
"\n",
|
||
"df_final = df_final.rename(columns={'Ciclo_x': 'Ciclo',\t'INICIO CICLO_x': 'INICIO CICLO',\t'FIM CICLO_x':'FIM CICLO' ,'DURAÇÃO_x':'DURAÇÃO',\n",
|
||
" \t'INICIO CICLO_y': 'INICIO CICLO SIMILAR' ,\t'FIM CICLO_y': 'FIM CICLO SIMILAR','DURAÇÃO_y':'DURAÇÃO CICLO SIMILAR'})"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 29,
|
||
"id": "b107e519",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"Index(['Histórico de Vendas do Ciclo 202501',\n",
|
||
" 'Histórico de Vendas do Ciclo 202502',\n",
|
||
" 'Histórico de Vendas do Ciclo 202503',\n",
|
||
" 'Histórico de Vendas do Ciclo 202504',\n",
|
||
" 'Histórico de Vendas do Ciclo 202505',\n",
|
||
" 'Histórico de Vendas do Ciclo 202506',\n",
|
||
" 'Histórico de Vendas do Ciclo Atual'],\n",
|
||
" dtype='object')"
|
||
]
|
||
},
|
||
"execution_count": 29,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_final.columns[40:47]"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 30,
|
||
"id": "8290853c",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"VENDA_SIMILAR_6_MESES= df_final.columns[40:47]\n",
|
||
"\n",
|
||
"df_final['Pico Vendas Similar Ultimos 6 ciclos'] = df_final[VENDA_SIMILAR_6_MESES].max(axis=1)\n",
|
||
"\n",
|
||
"\n",
|
||
"df_final['MEDIANA DO HISTÓRICO'] = df_final[colunas_mensais].dropna().median(axis=1)\n",
|
||
"\n",
|
||
"df_final['Vendas Ciclo Lançamento'] = df_final['Vendas Ciclo Lançamento'].fillna(0)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 31,
|
||
"id": "07f043f2",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/html": [
|
||
"<div>\n",
|
||
"<style scoped>\n",
|
||
" .dataframe tbody tr th:only-of-type {\n",
|
||
" vertical-align: middle;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe tbody tr th {\n",
|
||
" vertical-align: top;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe thead th {\n",
|
||
" text-align: right;\n",
|
||
" }\n",
|
||
"</style>\n",
|
||
"<table border=\"1\" class=\"dataframe\">\n",
|
||
" <thead>\n",
|
||
" <tr style=\"text-align: right;\">\n",
|
||
" <th></th>\n",
|
||
" <th>CANAL</th>\n",
|
||
" <th>med_por_canal</th>\n",
|
||
" </tr>\n",
|
||
" </thead>\n",
|
||
" <tbody>\n",
|
||
" <tr>\n",
|
||
" <th>0</th>\n",
|
||
" <td>CD</td>\n",
|
||
" <td>17.0</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>1</th>\n",
|
||
" <td>HIB</td>\n",
|
||
" <td>1.0</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>2</th>\n",
|
||
" <td>VD</td>\n",
|
||
" <td>12.0</td>\n",
|
||
" </tr>\n",
|
||
" </tbody>\n",
|
||
"</table>\n",
|
||
"</div>"
|
||
],
|
||
"text/plain": [
|
||
" CANAL med_por_canal\n",
|
||
"0 CD 17.0\n",
|
||
"1 HIB 1.0\n",
|
||
"2 VD 12.0"
|
||
]
|
||
},
|
||
"execution_count": 31,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"medi = df_final.groupby(['CANAL'])['MEDIANA DO HISTÓRICO'].max().reset_index()\n",
|
||
"medi = medi.rename(columns={'MEDIANA DO HISTÓRICO':'med_por_canal'})\n",
|
||
"medi"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 32,
|
||
"id": "94abddce",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final = pd.merge(left=df_final, right=medi,on='CANAL',how='inner')\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 33,
|
||
"id": "09cc2f82",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_vdc = pd.read_csv(r\"C:\\Users\\joao.herculano\\GRUPO GINSENG\\Assistência Suprimentos - 2025\\SUPRIMENTOS\\BD_LANÇAMENTOS\\BOT\\BOT - C11\\arquivos para geração da sugestão\\VENDAS VDC\\vendas_vdc22.02.csv\")\n",
|
||
"\n",
|
||
"\n",
|
||
"\n",
|
||
"df_vdc['DATA VENDA'] = pd.to_datetime(df_vdc['DATA VENDA'])\n",
|
||
"\n",
|
||
"# 'Dia' já está em formato datetime, então renomeamos para 'Data' diretamente\n",
|
||
"# ou apenas usamos 'Dia' como referência de data\n",
|
||
"\n",
|
||
"# Ordena o DataFrame para garantir que a cumulativa funcione corretamente\n",
|
||
"df_venda_diaria = df_venda_diaria.sort_values(by=['Unidade de Negócio', 'Código do Produto', 'Dia'])\n",
|
||
"\n",
|
||
"# Calcula a quantidade acumulada até o dia para cada grupo\n",
|
||
"df_vdc['Quantidade Acumulada vdc'] = (\n",
|
||
" df_vdc\n",
|
||
" .groupby(['PDVDEPARA.Practico', 'Código'])['Soma de Quantidade']\n",
|
||
" .cumsum()\n",
|
||
") # acumulado por grupo até a data da linha"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 34,
|
||
"id": "5a827c08",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/html": [
|
||
"<div>\n",
|
||
"<style scoped>\n",
|
||
" .dataframe tbody tr th:only-of-type {\n",
|
||
" vertical-align: middle;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe tbody tr th {\n",
|
||
" vertical-align: top;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe thead th {\n",
|
||
" text-align: right;\n",
|
||
" }\n",
|
||
"</style>\n",
|
||
"<table border=\"1\" class=\"dataframe\">\n",
|
||
" <thead>\n",
|
||
" <tr style=\"text-align: right;\">\n",
|
||
" <th></th>\n",
|
||
" <th>PDVDEPARA.Practico</th>\n",
|
||
" <th>Código</th>\n",
|
||
" <th>Ciclo vdc</th>\n",
|
||
" <th>Quantidade Acumulada vdc</th>\n",
|
||
" </tr>\n",
|
||
" </thead>\n",
|
||
" <tbody>\n",
|
||
" <tr>\n",
|
||
" <th>0</th>\n",
|
||
" <td>23701</td>\n",
|
||
" <td>48617</td>\n",
|
||
" <td>C202301</td>\n",
|
||
" <td>24</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>1</th>\n",
|
||
" <td>23701</td>\n",
|
||
" <td>50165</td>\n",
|
||
" <td>C202312</td>\n",
|
||
" <td>12</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>2</th>\n",
|
||
" <td>23701</td>\n",
|
||
" <td>50165</td>\n",
|
||
" <td>C202411</td>\n",
|
||
" <td>14</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>3</th>\n",
|
||
" <td>23701</td>\n",
|
||
" <td>50165</td>\n",
|
||
" <td>C202413</td>\n",
|
||
" <td>16</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>4</th>\n",
|
||
" <td>23701</td>\n",
|
||
" <td>50224</td>\n",
|
||
" <td>C202403</td>\n",
|
||
" <td>2</td>\n",
|
||
" </tr>\n",
|
||
" </tbody>\n",
|
||
"</table>\n",
|
||
"</div>"
|
||
],
|
||
"text/plain": [
|
||
" PDVDEPARA.Practico Código Ciclo vdc Quantidade Acumulada vdc\n",
|
||
"0 23701 48617 C202301 24\n",
|
||
"1 23701 50165 C202312 12\n",
|
||
"2 23701 50165 C202411 14\n",
|
||
"3 23701 50165 C202413 16\n",
|
||
"4 23701 50224 C202403 2"
|
||
]
|
||
},
|
||
"execution_count": 34,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_vdc = pd.merge(left=df_vdc,right=calendario[['Date','Ciclo']],left_on='DATA VENDA',right_on='Date',how='inner')\n",
|
||
"\n",
|
||
"df_vdc_agrupado = df_vdc.groupby(['PDVDEPARA.Practico',\t'Código','Ciclo'])['Quantidade Acumulada vdc'].max().reset_index()\n",
|
||
"\n",
|
||
"df_vdc_agrupado = df_vdc_agrupado.rename(columns={'Ciclo':'Ciclo vdc'})\n",
|
||
"\n",
|
||
"\n",
|
||
"df_vdc_agrupado.head()"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 35,
|
||
"id": "8ec14143",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final = pd.merge(left=df_final, right = df_vdc_agrupado, right_on=['Ciclo vdc','Código','PDVDEPARA.Practico'],left_on=['CICLO SIMILAR','PRODUTO SIMILAR','PDV'],how='left')\n",
|
||
"\n",
|
||
"df_final['Quantidade Acumulada vdc'] = df_final['Quantidade Acumulada vdc'].fillna(0)\n",
|
||
"\n",
|
||
"\n",
|
||
"df_final['Vendas Ciclo Lançamento'] = np.where(df_final['Quantidade Acumulada vdc']>0, df_final['Quantidade Acumulada vdc'], df_final['Vendas Ciclo Lançamento'])\n",
|
||
"\n",
|
||
"df_final = df_final.drop(columns='Quantidade Acumulada vdc')\n",
|
||
"\n",
|
||
"\n",
|
||
"df_final = df_final.drop(columns='Ciclo vdc')\n",
|
||
"\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 36,
|
||
"id": "27906593",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final['CRESCIMENTO_FINAL'] = df_final['CRESCIMENTO_GERAL'] + df_final['CRESCIMENTO'] #crescimento do pdv\n",
|
||
"\n",
|
||
"df_final['CRESCIMENTO_FINAL'] = np.where(df_final['CRESCIMENTO_GERAL'] + df_final['CRESCIMENTO']>0.8,0.8,df_final['CRESCIMENTO_GERAL'] + df_final['CRESCIMENTO'])\n",
|
||
"\n",
|
||
"df_final['CRESCIMENTO_FINAL'] = np.where(df_final['CRESCIMENTO_GERAL'] + df_final['CRESCIMENTO']<0,0,df_final['CRESCIMENTO_GERAL'] + df_final['CRESCIMENTO'])\n",
|
||
"\n",
|
||
"df_final['MEDIANA DO HISTÓRICO'] = np.where(df_final['MEDIANA DO HISTÓRICO']==0, df_final['med_por_canal'],df_final['MEDIANA DO HISTÓRICO'])\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 37,
|
||
"id": "5ba0586e",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"np.int64(0)"
|
||
]
|
||
},
|
||
"execution_count": 37,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_final['med_por_canal'].isna().sum()"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 38,
|
||
"id": "1a625e69",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"(170, 89)"
|
||
]
|
||
},
|
||
"execution_count": 38,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"\n",
|
||
"# Primeiro cálculo intermediário\n",
|
||
"df_final['PV GINSENG'] = np.where(df_final['CRESCIMENTO_FINAL'] * df_final['Vendas Ciclo Lançamento'] + df_final['Vendas Ciclo Lançamento'] < df_final['MEDIANA DO HISTÓRICO'],\n",
|
||
" round(df_final['CRESCIMENTO_FINAL'] * df_final['MEDIANA DO HISTÓRICO']+ df_final['MEDIANA DO HISTÓRICO'],0), \n",
|
||
" round(df_final['CRESCIMENTO_FINAL']*df_final['Vendas Ciclo Lançamento']+df_final['Vendas Ciclo Lançamento'],0))\n",
|
||
"\n",
|
||
"df_final['PV GINSENG'] = np.where(df_final['PV GINSENG'].isna(),df_final['med_por_canal'] ,df_final['PV GINSENG'])\n",
|
||
"\n",
|
||
"df_final.shape"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 39,
|
||
"id": "ad10c069",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final.drop(columns=df_final.columns[29:42],inplace=True)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 40,
|
||
"id": "f9bddbb1",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"Index(['PRODUTO LANÇAMENTO', 'DESCRIÇÃO DO LANÇAMENTO', 'PRODUTO SIMILAR',\n",
|
||
" 'DESCRIÇÃO SIMILAR', 'CICLO SIMILAR', 'FOCO', 'IAF', 'CATEGORIA',\n",
|
||
" 'MARCA', '% CONSUMIDOR', 'MECANICA CONSUMIDOR', '% REVENDEDOR',\n",
|
||
" 'MECANICA REVENDEDOR', 'TIPO DE PRODUTO', 'MATCH', 'PDV', 'CANAL',\n",
|
||
" 'DESCRIÇÃO PDV', 'PDV DESC', 'UF', 'ANALISTA', 'SUPERVISOR', 'status',\n",
|
||
" 'Classe', 'SKU', 'Descrição', 'Subcategoria', 'Lançamento',\n",
|
||
" 'Desativação', 'Histórico de Vendas do Ciclo 202503',\n",
|
||
" 'Histórico de Vendas do Ciclo 202504',\n",
|
||
" 'Histórico de Vendas do Ciclo 202505',\n",
|
||
" 'Histórico de Vendas do Ciclo 202506',\n",
|
||
" 'Histórico de Vendas do Ciclo Atual', 'Dias sem venda',\n",
|
||
" 'Projeção Próximo Ciclo', 'Projeção Próximo Ciclo + 1',\n",
|
||
" 'Promoção Próximo Ciclo', 'Promoção Próximo Ciclo + 1', 'Estoque Atual',\n",
|
||
" 'Estoque em Transito', 'Pedido Pendente',\n",
|
||
" 'Compra inteligente semanal/Sugestão de compra',\n",
|
||
" 'Compra inteligente Próximo Ciclo',\n",
|
||
" 'Compra inteligente Próximo Ciclo + 1', 'Item Desativado',\n",
|
||
" 'Data Prevista Regularização', 'Carteira Bloqueada Para Novos Pedidos',\n",
|
||
" 'Planograma', 'Quantidade por caixa', 'Preço Sell In', 'Quantidade',\n",
|
||
" 'Item analisado', 'Histórico de Vendas do Ciclo 202507', 'match_x',\n",
|
||
" 'CRESCIMENTO', 'Ciclo', 'INICIO CICLO', 'FIM CICLO', 'DURAÇÃO',\n",
|
||
" 'match_y', 'dias_ate_inicio', 'INICIO CICLO SIMILAR',\n",
|
||
" 'FIM CICLO SIMILAR', 'DURAÇÃO CICLO SIMILAR', 'Código do Produto',\n",
|
||
" 'Ciclo', 'Vendas Ciclo Lançamento', 'CRESCIMENTO_GERAL',\n",
|
||
" 'Pico Vendas Similar Ultimos 6 ciclos', 'MEDIANA DO HISTÓRICO',\n",
|
||
" 'med_por_canal', 'PDVDEPARA.Practico', 'Código', 'CRESCIMENTO_FINAL',\n",
|
||
" 'PV GINSENG'],\n",
|
||
" dtype='object')"
|
||
]
|
||
},
|
||
"execution_count": 40,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_final.columns"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 41,
|
||
"id": "fe73c93e",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"Index(['PRODUTO LANÇAMENTO', 'DESCRIÇÃO DO LANÇAMENTO', 'PRODUTO SIMILAR',\n",
|
||
" 'DESCRIÇÃO SIMILAR', 'CICLO SIMILAR', 'FOCO', 'IAF', 'CATEGORIA',\n",
|
||
" 'MARCA', '% CONSUMIDOR', 'MECANICA CONSUMIDOR', '% REVENDEDOR',\n",
|
||
" 'MECANICA REVENDEDOR', 'TIPO DE PRODUTO', 'MATCH', 'PDV', 'CANAL',\n",
|
||
" 'DESCRIÇÃO PDV', 'PDV DESC', 'UF', 'ANALISTA', 'SUPERVISOR',\n",
|
||
" 'Descrição', 'Histórico de Vendas do Ciclo 202503',\n",
|
||
" 'Histórico de Vendas do Ciclo 202504',\n",
|
||
" 'Histórico de Vendas do Ciclo 202505',\n",
|
||
" 'Histórico de Vendas do Ciclo 202506',\n",
|
||
" 'Histórico de Vendas do Ciclo Atual',\n",
|
||
" 'Histórico de Vendas do Ciclo 202507', 'Vendas Ciclo Lançamento',\n",
|
||
" 'Pico Vendas Similar Ultimos 6 ciclos', 'MEDIANA DO HISTÓRICO',\n",
|
||
" 'PDVDEPARA.Practico', 'Código', 'PV GINSENG'],\n",
|
||
" dtype='object')"
|
||
]
|
||
},
|
||
"execution_count": 41,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"\n",
|
||
"df_final.drop(columns=['status', 'Classe', 'SKU', 'Subcategoria', 'Lançamento',\n",
|
||
" 'Desativação','Dias sem venda',\n",
|
||
" 'Projeção Próximo Ciclo', 'Projeção Próximo Ciclo + 1',\n",
|
||
" 'Promoção Próximo Ciclo', 'Promoção Próximo Ciclo + 1', 'Estoque Atual',\n",
|
||
" 'Estoque em Transito', 'Pedido Pendente',\n",
|
||
" 'Compra inteligente semanal/Sugestão de compra',\n",
|
||
" 'Compra inteligente Próximo Ciclo',\n",
|
||
" 'Compra inteligente Próximo Ciclo + 1', 'Item Desativado',\n",
|
||
" 'Data Prevista Regularização', 'Carteira Bloqueada Para Novos Pedidos',\n",
|
||
" 'Planograma', 'Quantidade por caixa', 'Preço Sell In', 'Quantidade',\n",
|
||
" 'Item analisado', 'match_x',\n",
|
||
" 'CRESCIMENTO', 'Ciclo', 'INICIO CICLO', 'FIM CICLO', 'DURAÇÃO',\n",
|
||
" 'match_y', 'dias_ate_inicio', 'INICIO CICLO SIMILAR','med_por_canal', 'CRESCIMENTO_FINAL',\n",
|
||
" 'FIM CICLO SIMILAR', 'DURAÇÃO CICLO SIMILAR', 'Código do Produto','CRESCIMENTO_GERAL'],inplace=True)\n",
|
||
"df_final.columns"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 42,
|
||
"id": "66772a9a",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"Index(['Histórico de Vendas do Ciclo 202503',\n",
|
||
" 'Histórico de Vendas do Ciclo 202504',\n",
|
||
" 'Histórico de Vendas do Ciclo 202505',\n",
|
||
" 'Histórico de Vendas do Ciclo 202506',\n",
|
||
" 'Histórico de Vendas do Ciclo Atual'],\n",
|
||
" dtype='object')"
|
||
]
|
||
},
|
||
"execution_count": 42,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_final.columns[23:28]"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 43,
|
||
"id": "15b7149f",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final = df_final.rename(columns={df_final.columns[23]: \"C-4\", df_final.columns[24]: \"C-3\",df_final.columns[25]: \"C-2\",df_final.columns[26]: \"C-1\",df_final.columns[27]:'VENDAS CICLO ATUAL'})\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 44,
|
||
"id": "9333bc77",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"Index(['PRODUTO LANÇAMENTO', 'DESCRIÇÃO DO LANÇAMENTO', 'PRODUTO SIMILAR',\n",
|
||
" 'DESCRIÇÃO SIMILAR', 'CICLO SIMILAR', 'FOCO', 'IAF', 'CATEGORIA',\n",
|
||
" 'MARCA', '% CONSUMIDOR', 'MECANICA CONSUMIDOR', '% REVENDEDOR',\n",
|
||
" 'MECANICA REVENDEDOR', 'TIPO DE PRODUTO', 'MATCH', 'PDV', 'CANAL',\n",
|
||
" 'DESCRIÇÃO PDV', 'PDV DESC', 'UF', 'ANALISTA', 'SUPERVISOR',\n",
|
||
" 'DESCRIÇÃO', 'C-4', 'C-3', 'C-2', 'C-1', 'VENDAS CICLO ATUAL',\n",
|
||
" 'VENDAS CICLO LANÇAMENTO', 'PICO VENDAS SIMILAR ULTIMOS 6 CICLOS',\n",
|
||
" 'MEDIANA DO HISTÓRICO', 'PDVDEPARA.PRACTICO', 'CÓDIGO', 'PV GINSENG'],\n",
|
||
" dtype='object')"
|
||
]
|
||
},
|
||
"execution_count": 44,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_final.columns = df_final.columns.str.upper()\n",
|
||
"\n",
|
||
"df_final.drop(columns=df_final.filter(regex='HISTÓRICO DE VENDAS DO CICLO').columns, inplace=True)\n",
|
||
"\n",
|
||
"df_final.columns"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "5abd4bae",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final = df_final.drop(columns=['DESCRIÇÃO','MEDIANA DO HISTÓRICO','SKU'])"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 46,
|
||
"id": "62ce5c62",
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"(170, 32)"
|
||
]
|
||
},
|
||
"execution_count": 46,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"df_final.shape"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 47,
|
||
"id": "25cbff26",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final = df_final.reindex(columns=[\n",
|
||
" 'SUPERVISOR',\n",
|
||
" 'ANALISTA',\n",
|
||
" 'CANAL',\n",
|
||
" 'UF',\n",
|
||
" 'PDV',\n",
|
||
" 'PDV DESC',\n",
|
||
" 'PRODUTO LANÇAMENTO',\n",
|
||
" 'DESCRIÇÃO DO LANÇAMENTO',\n",
|
||
" 'MARCA',\n",
|
||
" 'CATEGORIA',\n",
|
||
" 'MECANICA CONSUMIDOR',\n",
|
||
" '% CONSUMIDOR',\n",
|
||
" 'MECANICA REVENDEDOR',\n",
|
||
" '% REVENDEDOR',\n",
|
||
" 'TIPO DE PRODUTO',\n",
|
||
" 'IAF',\n",
|
||
" 'FOCO',\n",
|
||
" 'SKU',\n",
|
||
" 'PRODUTO SIMILAR',\n",
|
||
" 'DESCRIÇÃO SIMILAR',\n",
|
||
" 'CICLO SIMILAR',\n",
|
||
" 'VENDAS CICLO LANÇAMENTO',\n",
|
||
" 'C-4',\n",
|
||
" 'C-3',\n",
|
||
" 'C-2',\n",
|
||
" 'C-1',\n",
|
||
" 'VENDAS CICLO ATUAL',\n",
|
||
" 'PICO VENDAS SIMILAR ULTIMOS 6 CICLOS',\n",
|
||
" 'PV GINSENG'])\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 48,
|
||
"id": "a3e80cb4",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final['SUGESTÃO METASELLIN'] = ''\n",
|
||
"df_final['SUGESTÃO ABASTECIMENTO'] = ''\n",
|
||
"df_final['SUGESTÃO COMERCIAL'] = ''\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 49,
|
||
"id": "2df3e2e9",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"df_final.to_excel(r'C:\\Users\\joao.herculano\\Documents\\sugestEUD.xlsx',index=False)"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 3
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython3",
|
||
"version": "3.13.2"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|