Home > Software engineering >  making a pandas tkinter interface, return string value from a sample()
making a pandas tkinter interface, return string value from a sample()

Time:09-27

trying to make a tkinter interface with pandas big database, how to return only the string relative to the selected column with a 'sample'

in the 'generateHand' function I generate a random line from my df, after that I take the 'Hand' column of this result and return to the value of the tkinter label, but it is coming as an object and not just the string I need

df = pd.read_csv(f'reports/report_IP_Full.csv')

def generateHand():
    hand = df.sample()['Hand']
    return hand

def handleButtton():
    hand = generateHand()
    lbl['text'] = hand

btn = Button(root, text='button', command=handleButtton)
btn.grid()

I also tried a version with return in .str

def generateHand():
    sample = df.sample()
    return sample['Hand'].str

enter image description here

CodePudding user response:

Solved with

def generateHand():
    sample = df.sample()
    return sample['Hand'].item()
  • Related