title: Display Dataframe as FastAPI output
body: <p>Dear Community Members,</p>
  <p>I am new to FastAPI and I am trying to display the pandas dataframe as FastAPI output but I am not able to get the desired result. Here is something I am have done:</p>
  <pre><code>from fastapi import FastAPI, Body, Request, Form
  from pydantic import BaseModel
  from fastapi.responses import HTMLResponse
  from fastapi.templating import Jinja2Templates
  import pandas as pd
  
  app = FastAPI()
  templates = Jinja2Templates(directory=&quot;htmlDirectory&quot;)
  
  class NameValues(BaseModel):
      Check : str = None
  
  @app.get(&quot;/home&quot;, response_class = HTMLResponse)
  def home(request:Request):
      return templates.TemplateResponse(&quot;introduction.html&quot;, {&quot;request&quot;: request})
  
  @app.post(&quot;/displayDF&quot;)
  async def handle_df(Check: str = Form(...)):
      print(&quot;User input : &quot;, Check)
  
      test_list = [[&quot;Joe&quot;, 34, &quot;Accounts&quot;, 10000], [&quot;Jack&quot;, 34, &quot;Chemistry&quot;, 20000]]
      data = pd.DataFrame(data=test_list, columns=[&quot;Name&quot;, &quot;Age&quot;, &quot;Dept.&quot;, &quot;Salary&quot;])
  
      return data.to_html()
  </code></pre>
  <p>The output displays like below screenshot:</p>
  <p><a href="https://i.stack.imgur.com/z63G2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z63G2.png" alt="enter image description here" /></a></p>
  <p>Is there a way to actually get the <strong>output in pandas dataframe format?</strong> Something like below :</p>
  <p><a href="https://i.stack.imgur.com/wlOYh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wlOYh.png" alt="enter image description here" /></a></p>
  <p>Also, below is the &quot;htmlDirectory&quot; code, if some changes has to be done here.</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;title&gt;Home&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h2&gt;Please enter a string in the space provided&lt;/h2&gt;
  
  &lt;form action=&quot;/displayDF&quot; method=&quot;post&quot;&gt;
      &lt;input type=&quot;text&quot; name=&quot;Check&quot;&gt;
      &lt;input type=&quot;submit&quot;&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>