<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>BIT</title>
<link>https://biitt.com/es/blog/machine-learning/</link>
<atom:link href="https://biitt.com/es/blog/machine-learning/index.xml" rel="self" type="application/rss+xml"/>
<description>BIT — Business Innovation Technology. Estadística, Machine Learning, Deep Learning, Big Data, MLOps e IoT: notebooks y artículos técnicos de Wilder Ramírez Delgado.</description>
<generator>quarto-1.8.27</generator>
<lastBuildDate>Sun, 23 Aug 2026 05:00:00 GMT</lastBuildDate>
<item>
  <title>Ejemplo: flujo completo de un notebook publicado en el blog</title>
  <dc:creator>Wilder Ramírez Delgado</dc:creator>
  <link>https://biitt.com/es/blog/machine-learning/ejemplo-post-completo/</link>
  <description><![CDATA[ 




<section id="análisis-ficticio-de-ventas-notebook-de-prueba-para-publicación" class="level1">
<h1>Análisis ficticio de ventas: notebook de prueba para publicación</h1>
<p><a href="TODO_URL_GITHUB"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"></a></p>
<p>Este notebook es una muestra compacta y realista para evaluar la conversión <strong>.ipynb → HTML</strong> y su publicación en distintos canales.</p>
<p>En esta demostración usamos datos sintéticos de ventas y una secuencia técnica típica:</p>
<ol type="1">
<li>Carga y creación de datos</li>
<li>Exploración inicial</li>
<li>Transformación</li>
<li>Estadísticas descriptivas</li>
<li>Visualizaciones estáticas e interactivas</li>
</ol>
<p>También incluimos elementos de formato: <em>cursiva</em>, <strong>negrita</strong>, listas y cita.</p>
<ul>
<li>Tema: ventas mensuales por región y canal</li>
<li>Fuente: datos generados en Python (sin archivos externos)</li>
<li>Reproducibilidad: semilla fija</li>
</ul>
<p>Más sobre buenas prácticas de visualización: <a href="https://plotly.com/python/">Plotly Fundamentals</a>.</p>
<blockquote class="blockquote">
<p>Nota: este cuaderno incluye caracteres en español (á, é, í, ó, ú, ñ) y símbolos como ≥, ≤, %, $, → para validar renderizado.</p>
</blockquote>
<p>URL de prueba visible: https://biitt.com/blog</p>
<p>Ecuación inline de margen: <img src="https://latex.codecogs.com/png.latex?m%20=%20%5Cfrac%7Bingresos%20-%20costos%7D%7Bingresos%7D">.</p>
<section id="sobre-el-autor" class="level2">
<h2 class="anchored" data-anchor-id="sobre-el-autor">👋 Sobre el autor</h2>
<p>Wilder Ramírez Delgado es Científico de Datos, Arquitecto de IA, Ingeniero Electrónico y Magíster en Analítica de Datos. CEO y fundador de Business Innovation Technology (BIT), consultor y docente universitario, trabaja en la intersección entre Data Science, Inteligencia Artificial, Big Data e IoT, transformando problemas reales en soluciones aplicadas.</p>
<p>De la teoría a la práctica, un problema a la vez.</p>
</section>
<section id="datos" class="level2">
<h2 class="anchored" data-anchor-id="datos">Datos</h2>
<p>Generamos un dataset pequeño de ventas con variación por mes, región, canal y categoría.</p>
<div id="4bdbdace" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;execution&quot;,&quot;value&quot;:{&quot;iopub.execute_input&quot;:&quot;2026-08-23T19:55:38.044998Z&quot;,&quot;iopub.status.busy&quot;:&quot;2026-08-23T19:55:38.044778Z&quot;,&quot;iopub.status.idle&quot;:&quot;2026-08-23T19:55:38.764441Z&quot;,&quot;shell.execute_reply&quot;:&quot;2026-08-23T19:55:38.762539Z&quot;}}" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb1-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> plotly.express <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> px</span>
<span id="cb1-5"></span>
<span id="cb1-6">np.random.seed(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>)</span>
<span id="cb1-7"></span>
<span id="cb1-8">meses <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.date_range(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2026-01-01"</span>, periods<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, freq<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MS"</span>)</span>
<span id="cb1-9">regiones <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Norte"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Centro"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sur"</span>]</span>
<span id="cb1-10">canales <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Online"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Retail"</span>]</span>
<span id="cb1-11">categorias <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Software"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Servicios"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Capacitación"</span>]</span>
<span id="cb1-12"></span>
<span id="cb1-13">rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb1-14"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> mes <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> meses:</span>
<span id="cb1-15">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> region <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> regiones:</span>
<span id="cb1-16">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> canal <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> canales:</span>
<span id="cb1-17">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> categoria <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> categorias:</span>
<span id="cb1-18">                base_unidades <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.randint(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">180</span>)</span>
<span id="cb1-19">                precio_unitario <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.uniform(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">140</span>)</span>
<span id="cb1-20">                descuento_pct <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.choice([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.00</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>], p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.35</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.30</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span>])</span>
<span id="cb1-21"></span>
<span id="cb1-22">                ingreso_bruto <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> base_unidades <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> precio_unitario</span>
<span id="cb1-23">                ingreso_neto <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ingreso_bruto <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> descuento_pct)</span>
<span id="cb1-24">                costo_estimado <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ingreso_neto <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> np.random.uniform(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.52</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.72</span>)</span>
<span id="cb1-25"></span>
<span id="cb1-26">                rows.append({</span>
<span id="cb1-27">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mes"</span>: mes,</span>
<span id="cb1-28">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region"</span>: region,</span>
<span id="cb1-29">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"canal"</span>: canal,</span>
<span id="cb1-30">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"categoria"</span>: categoria,</span>
<span id="cb1-31">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"unidades"</span>: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>(base_unidades),</span>
<span id="cb1-32">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"precio_unitario"</span>: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(precio_unitario, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-33">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"descuento_pct"</span>: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">float</span>(descuento_pct),</span>
<span id="cb1-34">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(ingreso_neto, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-35">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"costo_estimado"</span>: <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(costo_estimado, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-36">                })</span>
<span id="cb1-37"></span>
<span id="cb1-38">df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame(rows)</span>
<span id="cb1-39"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Filas generadas: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(df)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb1-40">df.head()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Filas generadas: 144</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="1">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">mes</th>
<th data-quarto-table-cell-role="th">region</th>
<th data-quarto-table-cell-role="th">canal</th>
<th data-quarto-table-cell-role="th">categoria</th>
<th data-quarto-table-cell-role="th">unidades</th>
<th data-quarto-table-cell-role="th">precio_unitario</th>
<th data-quarto-table-cell-role="th">descuento_pct</th>
<th data-quarto-table-cell-role="th">ingreso_neto</th>
<th data-quarto-table-cell-role="th">costo_estimado</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>2026-01-01</td>
<td>Norte</td>
<td>Online</td>
<td>Software</td>
<td>162</td>
<td>120.67</td>
<td>0.00</td>
<td>19548.80</td>
<td>13213.78</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>2026-01-01</td>
<td>Norte</td>
<td>Online</td>
<td>Servicios</td>
<td>80</td>
<td>59.82</td>
<td>0.00</td>
<td>4785.74</td>
<td>2544.18</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>2026-01-01</td>
<td>Norte</td>
<td>Online</td>
<td>Capacitación</td>
<td>147</td>
<td>76.70</td>
<td>0.00</td>
<td>11275.24</td>
<td>7330.91</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>2026-01-01</td>
<td>Norte</td>
<td>Retail</td>
<td>Software</td>
<td>112</td>
<td>137.14</td>
<td>0.10</td>
<td>13823.86</td>
<td>7775.47</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>2026-01-01</td>
<td>Norte</td>
<td>Retail</td>
<td>Servicios</td>
<td>123</td>
<td>139.26</td>
<td>0.05</td>
<td>16272.54</td>
<td>10452.35</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
</section>
<section id="exploración" class="level2">
<h2 class="anchored" data-anchor-id="exploración">Exploración</h2>
<p>Primero revisamos estructura, tipos y una tabla ancha para testear visualización en publicación.</p>
<div id="52d5d917" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;execution&quot;,&quot;value&quot;:{&quot;iopub.execute_input&quot;:&quot;2026-08-23T19:55:38.766476Z&quot;,&quot;iopub.status.busy&quot;:&quot;2026-08-23T19:55:38.766303Z&quot;,&quot;iopub.status.idle&quot;:&quot;2026-08-23T19:55:38.790572Z&quot;,&quot;shell.execute_reply&quot;:&quot;2026-08-23T19:55:38.789761Z&quot;}}" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Resumen rápido del dataset:"</span>)</span>
<span id="cb3-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(df.info())</span>
<span id="cb3-3"></span>
<span id="cb3-4">tabla_ancha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb3-5">    df.pivot_table(</span>
<span id="cb3-6">        index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"canal"</span>],</span>
<span id="cb3-7">        columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mes"</span>,</span>
<span id="cb3-8">        values<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>,</span>
<span id="cb3-9">        aggfunc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span></span>
<span id="cb3-10">    )</span>
<span id="cb3-11">    .<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb3-12">)</span>
<span id="cb3-13"></span>
<span id="cb3-14">tabla_ancha.columns <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [c.strftime(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y-%m"</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> tabla_ancha.columns]</span>
<span id="cb3-15">tabla_ancha</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Resumen rápido del dataset:
&lt;class 'pandas.DataFrame'&gt;
RangeIndex: 144 entries, 0 to 143
Data columns (total 9 columns):
 #   Column           Non-Null Count  Dtype         
---  ------           --------------  -----         
 0   mes              144 non-null    datetime64[us]
 1   region           144 non-null    str           
 2   canal            144 non-null    str           
 3   categoria        144 non-null    str           
 4   unidades         144 non-null    int64         
 5   precio_unitario  144 non-null    float64       
 6   descuento_pct    144 non-null    float64       
 7   ingreso_neto     144 non-null    float64       
 8   costo_estimado   144 non-null    float64       
dtypes: datetime64[us](1), float64(4), int64(1), str(3)
memory usage: 10.3 KB
None</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="2">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">2026-01</th>
<th data-quarto-table-cell-role="th">2026-02</th>
<th data-quarto-table-cell-role="th">2026-03</th>
<th data-quarto-table-cell-role="th">2026-04</th>
<th data-quarto-table-cell-role="th">2026-05</th>
<th data-quarto-table-cell-role="th">2026-06</th>
<th data-quarto-table-cell-role="th">2026-07</th>
<th data-quarto-table-cell-role="th">2026-08</th>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">region</th>
<th data-quarto-table-cell-role="th">canal</th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th rowspan="2" data-quarto-table-cell-role="th" data-valign="top">Centro</th>
<th data-quarto-table-cell-role="th">Online</th>
<td>35186.0</td>
<td>49554.0</td>
<td>42293.0</td>
<td>32025.0</td>
<td>42012.0</td>
<td>24524.0</td>
<td>48242.0</td>
<td>15813.0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Retail</th>
<td>18406.0</td>
<td>28715.0</td>
<td>33445.0</td>
<td>33557.0</td>
<td>27430.0</td>
<td>24748.0</td>
<td>43131.0</td>
<td>30073.0</td>
</tr>
<tr class="odd">
<th rowspan="2" data-quarto-table-cell-role="th" data-valign="top">Norte</th>
<th data-quarto-table-cell-role="th">Online</th>
<td>35610.0</td>
<td>32800.0</td>
<td>26948.0</td>
<td>31399.0</td>
<td>34495.0</td>
<td>37233.0</td>
<td>36724.0</td>
<td>28596.0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Retail</th>
<td>37583.0</td>
<td>26243.0</td>
<td>38964.0</td>
<td>38199.0</td>
<td>29921.0</td>
<td>19354.0</td>
<td>28893.0</td>
<td>19668.0</td>
</tr>
<tr class="odd">
<th rowspan="2" data-quarto-table-cell-role="th" data-valign="top">Sur</th>
<th data-quarto-table-cell-role="th">Online</th>
<td>23018.0</td>
<td>43835.0</td>
<td>30914.0</td>
<td>25818.0</td>
<td>20949.0</td>
<td>23586.0</td>
<td>23635.0</td>
<td>39535.0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">Retail</th>
<td>26645.0</td>
<td>27783.0</td>
<td>29011.0</td>
<td>35379.0</td>
<td>45683.0</td>
<td>26238.0</td>
<td>36963.0</td>
<td>25284.0</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
</section>
<section id="transformación" class="level2">
<h2 class="anchored" data-anchor-id="transformación">Transformación</h2>
<p>Creamos variables derivadas para análisis de margen y segmentación de desempeño.</p>
<div id="46595950" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;execution&quot;,&quot;value&quot;:{&quot;iopub.execute_input&quot;:&quot;2026-08-23T19:55:38.792723Z&quot;,&quot;iopub.status.busy&quot;:&quot;2026-08-23T19:55:38.792575Z&quot;,&quot;iopub.status.idle&quot;:&quot;2026-08-23T19:55:38.810610Z&quot;,&quot;shell.execute_reply&quot;:&quot;2026-08-23T19:55:38.809514Z&quot;}}" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> etiquetar_rendimiento(margen_pct, ingreso_neto):</span>
<span id="cb5-2">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (margen_pct <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.40</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">and</span> (ingreso_neto <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12000</span>):</span>
<span id="cb5-3">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Alto"</span></span>
<span id="cb5-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (margen_pct <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.30</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">and</span> (ingreso_neto <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9000</span>):</span>
<span id="cb5-5">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Medio"</span></span>
<span id="cb5-6">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bajo"</span></span>
<span id="cb5-7"></span>
<span id="cb5-8"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> preparar_dataset(df_base):</span>
<span id="cb5-9">    df_t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_base.copy()</span>
<span id="cb5-10"></span>
<span id="cb5-11">    df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"costo_estimado"</span>]</span>
<span id="cb5-12">    df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margen_pct"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.where(</span>
<span id="cb5-13">        df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb5-14">        df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>],</span>
<span id="cb5-15">        np.nan</span>
<span id="cb5-16">    )</span>
<span id="cb5-17"></span>
<span id="cb5-18">    df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ticket_promedio"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.where(</span>
<span id="cb5-19">        df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"unidades"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb5-20">        df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"unidades"</span>],</span>
<span id="cb5-21">        np.nan</span>
<span id="cb5-22">    )</span>
<span id="cb5-23"></span>
<span id="cb5-24">    df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rendimiento"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb5-25">        etiquetar_rendimiento(m, i)</span>
<span id="cb5-26">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> m, i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">zip</span>(df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margen_pct"</span>], df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>])</span>
<span id="cb5-27">    ]</span>
<span id="cb5-28"></span>
<span id="cb5-29">    df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mes_nombre"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mes"</span>].dt.strftime(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%b"</span>)</span>
<span id="cb5-30">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> df_t</span>
<span id="cb5-31"></span>
<span id="cb5-32">df_t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> preparar_dataset(df)</span>
<span id="cb5-33"></span>
<span id="cb5-34"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Transformación completada → columnas nuevas: utilidad, margen_pct, ticket_promedio, rendimiento"</span>)</span>
<span id="cb5-35">df_t[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"canal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margen_pct"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rendimiento"</span>]].head()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Transformación completada → columnas nuevas: utilidad, margen_pct, ticket_promedio, rendimiento</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="3">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">mes</th>
<th data-quarto-table-cell-role="th">region</th>
<th data-quarto-table-cell-role="th">canal</th>
<th data-quarto-table-cell-role="th">ingreso_neto</th>
<th data-quarto-table-cell-role="th">utilidad</th>
<th data-quarto-table-cell-role="th">margen_pct</th>
<th data-quarto-table-cell-role="th">rendimiento</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>2026-01-01</td>
<td>Norte</td>
<td>Online</td>
<td>19548.80</td>
<td>6335.02</td>
<td>0.324062</td>
<td>Medio</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>2026-01-01</td>
<td>Norte</td>
<td>Online</td>
<td>4785.74</td>
<td>2241.56</td>
<td>0.468383</td>
<td>Bajo</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>2026-01-01</td>
<td>Norte</td>
<td>Online</td>
<td>11275.24</td>
<td>3944.33</td>
<td>0.349822</td>
<td>Medio</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>2026-01-01</td>
<td>Norte</td>
<td>Retail</td>
<td>13823.86</td>
<td>6048.39</td>
<td>0.437533</td>
<td>Alto</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>2026-01-01</td>
<td>Norte</td>
<td>Retail</td>
<td>16272.54</td>
<td>5820.19</td>
<td>0.357669</td>
<td>Medio</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
</section>
<section id="estadísticas" class="level2">
<h2 class="anchored" data-anchor-id="estadísticas">Estadísticas</h2>
<p>Calculamos métricas agregadas y una tabla resumen con Pandas.</p>
<p>Ecuación en bloque para referencia: <img src="https://latex.codecogs.com/png.latex?%0AROI%20=%20%5Cfrac%7B%5Csum%20utilidad%7D%7B%5Csum%20costo%7D%20%5Ctimes%20100%0A"> Si <img src="https://latex.codecogs.com/png.latex?ROI%20eq%2020%5C%25">, consideramos un desempeño saludable.</p>
<div id="eaeac912" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;execution&quot;,&quot;value&quot;:{&quot;iopub.execute_input&quot;:&quot;2026-08-23T19:55:38.812524Z&quot;,&quot;iopub.status.busy&quot;:&quot;2026-08-23T19:55:38.812343Z&quot;,&quot;iopub.status.idle&quot;:&quot;2026-08-23T19:55:38.830030Z&quot;,&quot;shell.execute_reply&quot;:&quot;2026-08-23T19:55:38.829278Z&quot;}}" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1">resumen_general <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb7-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_total"</span>: df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(),</span>
<span id="cb7-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"costo_total"</span>: df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"costo_estimado"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(),</span>
<span id="cb7-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad_total"</span>: df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(),</span>
<span id="cb7-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margen_promedio"</span>: df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margen_pct"</span>].mean(),</span>
<span id="cb7-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ticket_promedio"</span>: df_t[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ticket_promedio"</span>].mean()</span>
<span id="cb7-7">}</span>
<span id="cb7-8"></span>
<span id="cb7-9">roi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (resumen_general[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad_total"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> resumen_general[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"costo_total"</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb7-10"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Ingreso total: $</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>resumen_general[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'ingreso_total'</span>]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:,.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb7-11"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Utilidad total: $</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>resumen_general[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'utilidad_total'</span>]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:,.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb7-12"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Margen promedio: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>resumen_general[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'margen_promedio'</span>]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.2%}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb7-13"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"ROI estimado: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>roi<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.2f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">%"</span>)</span>
<span id="cb7-14"></span>
<span id="cb7-15">tabla_resumen <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb7-16">    df_t.groupby([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"canal"</span>], as_index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb7-17">    .agg(</span>
<span id="cb7-18">        ingreso_total<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>),</span>
<span id="cb7-19">        utilidad_total<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>),</span>
<span id="cb7-20">        margen_promedio<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margen_pct"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>),</span>
<span id="cb7-21">        unidades_total<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"unidades"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>)</span>
<span id="cb7-22">    )</span>
<span id="cb7-23">    .sort_values(by<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_total"</span>, ascending<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb7-24">)</span>
<span id="cb7-25"></span>
<span id="cb7-26">tabla_resumen</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Ingreso total: $1,516,059.34
Utilidad total: $586,009.69
Margen promedio: 38.69%
ROI estimado: 63.01%</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="4">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">region</th>
<th data-quarto-table-cell-role="th">canal</th>
<th data-quarto-table-cell-role="th">ingreso_total</th>
<th data-quarto-table-cell-role="th">utilidad_total</th>
<th data-quarto-table-cell-role="th">margen_promedio</th>
<th data-quarto-table-cell-role="th">unidades_total</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>Centro</td>
<td>Online</td>
<td>289649.28</td>
<td>110873.94</td>
<td>0.380867</td>
<td>2886</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">2</th>
<td>Norte</td>
<td>Online</td>
<td>263805.07</td>
<td>104656.98</td>
<td>0.400802</td>
<td>2857</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">5</th>
<td>Sur</td>
<td>Retail</td>
<td>252984.68</td>
<td>95124.82</td>
<td>0.376046</td>
<td>2894</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>Centro</td>
<td>Retail</td>
<td>239504.68</td>
<td>90415.85</td>
<td>0.382808</td>
<td>2800</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">3</th>
<td>Norte</td>
<td>Retail</td>
<td>238826.14</td>
<td>95155.41</td>
<td>0.392284</td>
<td>2866</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">4</th>
<td>Sur</td>
<td>Online</td>
<td>231289.49</td>
<td>89782.69</td>
<td>0.388458</td>
<td>2712</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
</section>
<section id="visualizaciones" class="level2">
<h2 class="anchored" data-anchor-id="visualizaciones">Visualizaciones</h2>
<p>Incluimos dos gráficas con Matplotlib y una interactiva con Plotly.</p>
<div id="85f3bf86" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;execution&quot;,&quot;value&quot;:{&quot;iopub.execute_input&quot;:&quot;2026-08-23T19:55:38.831814Z&quot;,&quot;iopub.status.busy&quot;:&quot;2026-08-23T19:55:38.831675Z&quot;,&quot;iopub.status.idle&quot;:&quot;2026-08-23T19:55:39.007025Z&quot;,&quot;shell.execute_reply&quot;:&quot;2026-08-23T19:55:39.006195Z&quot;}}" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1">ventas_mensuales <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_t.groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mes"</span>, as_index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb9-2"></span>
<span id="cb9-3">plt.style.use(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggplot"</span>)</span>
<span id="cb9-4">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.5</span>))</span>
<span id="cb9-5">ax.plot(ventas_mensuales[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mes"</span>], ventas_mensuales[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>], marker<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"o"</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb9-6">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Evolución de ingresos netos por mes"</span>)</span>
<span id="cb9-7">ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mes"</span>)</span>
<span id="cb9-8">ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ingreso neto ($)"</span>)</span>
<span id="cb9-9">ax.tick_params(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>, rotation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>)</span>
<span id="cb9-10">plt.tight_layout()</span>
<span id="cb9-11">plt.show()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://biitt.com/es/blog/machine-learning/ejemplo-post-completo/index_files/figure-html/cell-6-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<div id="893af117" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;execution&quot;,&quot;value&quot;:{&quot;iopub.execute_input&quot;:&quot;2026-08-23T19:55:39.009684Z&quot;,&quot;iopub.status.busy&quot;:&quot;2026-08-23T19:55:39.009520Z&quot;,&quot;iopub.status.idle&quot;:&quot;2026-08-23T19:55:39.126155Z&quot;,&quot;shell.execute_reply&quot;:&quot;2026-08-23T19:55:39.124818Z&quot;}}" data-execution_count="6">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1">utilidad_region <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df_t.groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region"</span>, as_index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad"</span>].<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb10-2"></span>
<span id="cb10-3">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.5</span>))</span>
<span id="cb10-4">bars <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ax.bar(utilidad_region[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region"</span>], utilidad_region[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad"</span>], color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1f77b4"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2ca02c"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ff7f0e"</span>])</span>
<span id="cb10-5">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Utilidad acumulada por región"</span>)</span>
<span id="cb10-6">ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Región"</span>)</span>
<span id="cb10-7">ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Utilidad ($)"</span>)</span>
<span id="cb10-8"></span>
<span id="cb10-9"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> bars:</span>
<span id="cb10-10">    y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> b.get_height()</span>
<span id="cb10-11">    ax.text(b.get_x() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> b.get_width() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, y, <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"$</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:,.0f}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, ha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span>, va<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>, fontsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb10-12"></span>
<span id="cb10-13">plt.tight_layout()</span>
<span id="cb10-14">plt.show()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://biitt.com/es/blog/machine-learning/ejemplo-post-completo/index_files/figure-html/cell-7-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<div id="6f4ab2e2" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;execution&quot;,&quot;value&quot;:{&quot;iopub.execute_input&quot;:&quot;2026-08-23T19:55:39.128457Z&quot;,&quot;iopub.status.busy&quot;:&quot;2026-08-23T19:55:39.128299Z&quot;,&quot;iopub.status.idle&quot;:&quot;2026-08-23T19:55:40.798519Z&quot;,&quot;shell.execute_reply&quot;:&quot;2026-08-23T19:55:40.797440Z&quot;}}" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1">scatter_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb11-2">    df_t.groupby([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"canal"</span>], as_index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb11-3">    .agg(</span>
<span id="cb11-4">        ingreso_total<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_neto"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>),</span>
<span id="cb11-5">        utilidad_total<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>),</span>
<span id="cb11-6">        margen_promedio<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margen_pct"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>)</span>
<span id="cb11-7">    )</span>
<span id="cb11-8">)</span>
<span id="cb11-9"></span>
<span id="cb11-10">fig <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> px.scatter(</span>
<span id="cb11-11">    scatter_df,</span>
<span id="cb11-12">    x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ingreso_total"</span>,</span>
<span id="cb11-13">    y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"utilidad_total"</span>,</span>
<span id="cb11-14">    size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margen_promedio"</span>,</span>
<span id="cb11-15">    color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region"</span>,</span>
<span id="cb11-16">    symbol<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"canal"</span>,</span>
<span id="cb11-17">    hover_data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margen_promedio"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":.2%"</span>},</span>
<span id="cb11-18">    title<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ingreso vs utilidad por región/canal (interactivo)"</span></span>
<span id="cb11-19">)</span>
<span id="cb11-20">fig.update_layout(template<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plotly_white"</span>)</span>
<span id="cb11-21">fig.show()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<pre><code>Unable to display output for mime type(s): application/vnd.plotly.v1+json</code></pre>
</div>
</div>
<section id="versión-estática-del-gráfico-interactivo" class="level3">
<h3 class="anchored" data-anchor-id="versión-estática-del-gráfico-interactivo">Versión estática del gráfico interactivo</h3>
<p>Medium (y otros importadores que no ejecutan JavaScript) no pueden mostrar el widget interactivo de Plotly de arriba. Por eso generamos también una versión estática (PNG) del mismo gráfico, para que sobreviva en plataformas sin soporte de JS.</p>
<div id="8111b00d" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;execution&quot;,&quot;value&quot;:{&quot;iopub.execute_input&quot;:&quot;2026-08-23T19:55:40.801023Z&quot;,&quot;iopub.status.busy&quot;:&quot;2026-08-23T19:55:40.800847Z&quot;,&quot;iopub.status.idle&quot;:&quot;2026-08-23T19:55:44.663920Z&quot;,&quot;shell.execute_reply&quot;:&quot;2026-08-23T19:55:44.662423Z&quot;}}" data-execution_count="8">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> IPython.display <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> Image, display</span>
<span id="cb13-2"></span>
<span id="cb13-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Exportamos el mismo gráfico de Plotly como imagen estática (requiere el paquete kaleido).</span></span>
<span id="cb13-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Esta versión sí es un &lt;img&gt; normal en el HTML final, así que sobrevive al import de Medium.</span></span>
<span id="cb13-5">fig.update_layout(width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">900</span>, height<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">520</span>)</span>
<span id="cb13-6">fig.write_image(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plotly_scatter_static.png"</span>, scale<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb13-7"></span>
<span id="cb13-8">display(Image(filename<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plotly_scatter_static.png"</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://biitt.com/es/blog/machine-learning/ejemplo-post-completo/index_files/figure-html/cell-9-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
</section>
<section id="conclusiones" class="level2">
<h2 class="anchored" data-anchor-id="conclusiones">Conclusiones</h2>
<p>Este notebook cumple con una estructura técnica publicable: <strong>Título → Introducción → Datos → Exploración → Transformación → Estadísticas → Visualizaciones → Conclusiones</strong>.</p>
<p>Hallazgos ficticios: - El ingreso y la utilidad muestran variación moderada por mes. - Existen diferencias entre regiones y canales en margen promedio. - El formato incluye componentes útiles para validar exportación a HTML, blog y Medium.</p>
<p>Checklist visual rápida: - Caracteres especiales: á, é, í, ó, ú, ñ - Símbolos: ≥, ≤, %, $, → - Tabla ancha y bloque de código largo - Gráficas estáticas + gráfica interactiva</p>
<section id="te-sirvió" class="level3">
<h3 class="anchored" data-anchor-id="te-sirvió">💬 ¿Te sirvió?</h3>
<p>Deja en los comentarios <strong>una duda o un caso donde aplicarías esto</strong> — respondo todos. Sígueme para no perderte el próximo artículo de la serie y comparte con alguien que esté aprendiendo análisis de datos.</p>
<p>👉 El código completo está disponible para ejecutar directamente.</p>


</section>
</section>
</section>

 ]]></description>
  <category>ejemplo</category>
  <category>machine-learning</category>
  <guid>https://biitt.com/es/blog/machine-learning/ejemplo-post-completo/</guid>
  <pubDate>Sun, 23 Aug 2026 05:00:00 GMT</pubDate>
  <media:content url="https://biitt.com/es/blog/machine-learning/ejemplo-post-completo/plotly_scatter_static.png" medium="image" type="image/png" height="83" width="144"/>
</item>
</channel>
</rss>
