Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda