[Python] Return a single row and reference that row from a dataframe in python like mysql

Discussão em 'Python' iniciado por Stack, Março 2, 2025.

  1. Stack

    Stack Membro Participativo

    How do I return a result from a dataframe like you would in mysql, like :

    select columnx, from table where columny='thisvalue' and coloumnx='thisvalue2'


    I would expect it to return a single value from the row where columny and columx = the values I searched for. In my example there's only going to be one row with those values.

    Then, how would I print that value?

    Thank you!

    My work so far.. :

    from pandas.io.html import import_optional_dependency
    import requests
    import pandas as pd
    from bs4 import BeautifulSoup
    import lxml




    smurl = 'GOOGLE DOCS URL WITH TABLE OF DATA'
    smdata = requests.get(smurl).content
    smdata = smdata.decode('UTF-8')
    smlist = pd.read_html(smdata)
    smdf = smlist[-1]
    smdf.columns = smdf.iloc[0]
    smdf = smdf[1:]
    smdf = smdf.sort_values(['x-coordinate', 'y-coordinate'], ascending=[True, True])

    ccountmax = max(smdf['y-coordinate'])
    rcountmax = max(smdf['x-coordinate'])
    rcount= 0
    ccount = 0

    print(smdf)
    print(rcountmax)
    print(ccountmax)

    for x in range(0, int(rcountmax)):
    for y in range(0, int(ccountmax)):
    char = smdf[int(smdf['x-coordinate']) == x & int(smdf['y-coordinate']) == y]
    if char.empty:
    print(' ', end='')
    else:
    print(char['character'], end='')
    print('\n')

    Continue reading...

Compartilhe esta Página