2

I am currently practicing pandas

I am using some pokemon data as a practice https://gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6

i want to make a program that allows the user to input their queries and I will return the result that they need.

i have a little problem where if i show the results of my pandas query in pysimplegui, it shows an ''ugly'' result unlike in the terminal that is ''pretty'. To be more clear with my problem, here is an example.

If I query this:

pic1

the result after i press "search" will be

pic2

but if i look at the results in the terminal, it looks like this

pic3

here is my working code


import pandas as pd
import PySimpleGUI as sg

pd.set_option('display.max_rows', None)
df = pd.read_csv(r'PATH HERE')

layout = [  [sg.Text('This is a basic searcher \nPlease input your search parameters')],
            [sg.Text('Name'), sg.Input(key='Name')],
            [sg.Text('Type 1'), sg.Input(key='Type 1')],
            [sg.Text('Type 2'), sg.Input(key='Type 2')],
            [sg.Text('Total'), sg.Input(key='Total')],
            [sg.Text('Generation'), sg.Input(key='Generation')],
            [sg.Button('Search'), sg.Button('Close')]
]


window = sg.Window('Pokemon Database Query', layout).Finalize()


while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'Close':
        break
    if event == 'Search':
        df_query = 'df.loc['
        for key,value in values.items():
            if value != '':
                if value.isnumeric():
                    df_query += f'''(df['{key}'] == {value})&'''
                else:
                    df_query += f'''(df['{key}'] == '{value}')&'''
        df_query = df_query[:-1] + ']'
        sg.popup_scrolled('Result', eval(df_query))
window.close()

thank you

kalimdor18
  • 99
  • 13

1 Answers1

0

The ugliness of the wrapping can be improved by specifying the window size to be returned. size=(columns,rows)`

sg.popup_scrolled('Result', eval(df_query), size=(100,40))
r-beginners
  • 31,170
  • 3
  • 14
  • 32
  • i already tried to do this, but it still is ugly.. i set it to size = (1280, 720) which is basically my whole screen.. and this is what it looked like https://ibb.co/sbgQBFw – kalimdor18 Aug 31 '20 at 14:12
  • Why not try this instead of this? Table()` instead of `sg.popup_scrolled()`.Here's a sample, even if it's [official](https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Table_Pandas.py). – r-beginners Sep 01 '20 at 01:31