Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
How to filter a df based on user input

I am trying to implement an auto complete feature on a flask app where I want that when the user input characters, a windows will appear with options with stock symbols.

My current /search html is basic intentionally becaue I want to debug as I go along

def search():
    from ftplib import FTP

    directory = 'symboldirectory'
    filenames = ('otherlisted.txt', 'nasdaqlisted.txt')

    ftp = FTP('ftp.nasdaqtrader.com')
    ftp.login()
    ftp.cwd(directory)

    for item in filenames:
        ftp.retrbinary('RETR {0}'.format(item), open(item, 'wb').write)

    ftp.quit()

    # Create pandas dataframes from the nasdaqlisted and otherlisted files.
    nasdaq_exchange_info = pd.read_csv('nasdaqlisted.txt', '|')
    other_exchange_info = pd.read_csv('otherlisted.txt', '|')
    nasdaq_exchange_info=nasdaq_exchange_info.query('ETF == ETF')
    nasdaq_exchange_info = nasdaq_exchange_info.rename(columns={'Security Name': 'Security_Name'})
    nasdaq_exchange_info=nasdaq_exchange_info.query("Security_Name.str.contains(request.args.get('q'), case=False)")
    print(nasdaq_exchange_info)
    return render_template("search.html", nasdaq_exchange_info=nasdaq_exchange_info)

My issue is in

    nasdaq_exchange_info=nasdaq_exchange_info.query("Security_Name.str.contains(request.args.get('q'), case=False)")
print(nasdaq_exchange_info)

I get name 'request' is not defined error (if I'll input Security_Name.str.contains('apple', case=False) for example it will get printed.) Also I tried every variation I could think of but I get syntax error.

My html look like this:

<body>

        <input autocomplete="off" autofocus placeholder="Query" type="text">

        <ul></ul>

        <script>

            let input = document.querySelector('input');
            input.addEventListener('input', async function() {
                let response = await fetch('/search?q=' + input.value);
                let nasdaq_exchange_info = await response.json();
                let html = '';
                for (let symbol in nasdaq_exchange_info) {
                    let ticker = nasdaq_exchange_info[Security_Name].symbol;
                    html += '<li>' + ticker + '</li>';
                }
                document.querySelector('ul').innerHTML = html;
            });

        </script>

    </body>

Is there a knwon way of implementing the user typing in q and serach the db for it? I know how to do it in a db using sql but I am trying to avoid that.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

try applying fstrings like that:

nasdaq_exchange_info=nasdaq_exchange_info.query(f"Security_Name.str.contains({request.args.get('q')}, case=False)")
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda