title: Rendering pandas DataFrame to html on Flask
body: <p>Can anyone give me some tips or links to investigate how to remedy a <code>df.describe()</code> in a web browser thru a flask app?</p>
  
  <p>For example if I <code>print(df.describe())</code> in IPython this comes thru in a nice format:</p>
  
  <pre><code>     kW
  count  28219.000000
  mean     134.723654
  std       46.849081
  min       24.300000
  25%       91.300000
  50%      135.900000
  75%      168.600000
  max      313.900000
  </code></pre>
  
  <p>But if I attempt this with a render template pass the data as string::</p>
  
  <pre><code>maxStatsStr = str(df.describe())
  
  resp = make_response(render_template('table.html',
  maxStatsStr=maxStatsStr))
  
  return resp
  </code></pre>
  
  <p>To the front end HTML file with Jinja syntax:</p>
  
  <pre><code>&lt;p&gt;{{maxStatsStr}}&lt;/p&gt;
  </code></pre>
  
  <p>This shows up in the browser</p>
  
  <pre><code>kW count 34880.000000 mean 79.687947 std 42.909287 min 12.200000 25% 38.800000 50% 73.400000 75% 113.200000 max 292.800000
  </code></pre>
  
  <p>Would a better method be creating like a table somehow, and using a for loop with Jinja to display the data? On the backend I just dont know how to prepare a <code>df.describe()</code> to be rendered as a table, like this below:</p>
  
  <pre><code>{% for table in tables %}
              {{ table|safe }}
  {% endfor %}
  </code></pre>
  
  <p><strong>FINAL CODE USED</strong></p>
  
  <pre><code>statsInfoStr = df.describe().to_html()
  
  resp = make_response(render_template('table.html',
  maxDateStr=maxDateStr,
  
  tables=[statsInfoStr], titles=df.describe().T))
  return resp
  </code></pre>
  
  <p><code>table.html</code> jinja to loop over data:</p>
  
  <pre><code>        &lt;h2&gt;Summary Statistics&lt;/h2&gt;
          {% for table in tables %}
                      {{ table|safe }}
          {% endfor %}
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>