title: Creating Search function on CSV file through flask
body: <p>I am a beginner at creating a web API using Flask. I am trying to use flask rest API to search and get data from the CSV file to the page through some keywords. More specifically, the goal is to input string as a keyword on /search/&lt;user_input&gt; which will be searched throughout the CSV file and pull all the similar strings and give the entre rows of data.</p>
  <p>I have tried to upload the CSV file using python flask, but I have no idea about searching.
  Anyone can suggest me solutions?</p>
  <p>The CSV file is this :
  <a href="https://i.stack.imgur.com/sbgnL.png" rel="nofollow noreferrer">enter image description here</a></p>
  <ul>
  <li>List item</li>
  </ul>
  <p>My code to upload the CSV file is here:</p>
  <pre><code>from flask import Flask, render_template, request, make_response
  import pandas as pd
  import csv
  
  app = Flask(__name__)
  
  @app.route('/', methods=['GET', 'POST'])
  def index():
       # Set The upload HTML template '\templates\index.html'
      return render_template('index.html')
  
  @app.route('/data', methods=['GET', 'POST'])
  def data():
      if request.method == 'POST':
          f = request.form['csvfile']
          data = []
          with open(f) as file:
              csvfile = csv.reader(file)
              for row in csvfile:
                  data.append(row)
          data = pd.DataFrame(data)
          return render_template('data.html', data=data.to_html(header=False, index=False))
  
  
  if (__name__ == &quot;__main__&quot;):
      app.run(port=5000, threaded=True, debug=True)
  </code></pre>