Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Objective:

I am writing an application (using Tkinter, Python 3.0 - ubuntu). The event trigger is user input a float, user presses a button; then 'calculate' function compares a column from a pandas dataframe (made from a .csv) to the user's input.

It should return the five rows.

Those rows are determined by the proximity (closeness) of the user's number compared with all floats in a particular column of the dataframe the function created using pandas. Next, it should return summary stats for (one 0f the columns) from those 5 returned rows. (Note: pandas' df.column.describe() will suffice for now).

(I have a pressing deadline, so any thoughtful suggestions will be met with immediate good karma and instant upvoting). :-)

Error1:

   **TypeError: unsupported operand type(s) for -: 'float' and 'instance'**

Note1:

Presumably, the compiler considers the floats from dataframe and 'instance' my declared es_in=DoubleVar().

Modification: Tkinter has no 'FloatVar()'. I cast float(es_in). It gives:

Error2:

  AttributeError: DoubleVar instance has no attribute '__float__'

This is probably a glaring error for some of you, but I'd like to understand why.

import pandas as pd
from Tkinter import *
import ttk

def calculate(*args):
    try:
        df=pd.read_csv('master_pl.csv')

Note2:

The following line gives me the five 'closest' rows. The error is generated from this line: where I compare a column of my dataframe: df["ES"], to the user-defined input called es_in.

        df.ix[(df["ES"][:]-es_in).abs().argsort()[:5]]

     except ValueError:
       pass


  <___calculate_function_ends_here___>
   # GUI code continues...


root = Tk()
root.title("Cluster Program")

mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

The user defined input is here:

es_in = DoubleVar()

es_entry = ttk.Entry(mainframe, width=7)
es_entry.grid(column=2, row=1, sticky=(W, E))


ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=3, sticky=W)

 ttk.Label(mainframe, text="ES").grid(column=3, row=1, sticky=W)
 ttk.Label(mainframe, text="output_fiveclosestrows").grid(column=3, row=2, sticky=W)



es_entry.focus()
root.bind('<Return>', calculate) 


<end>
share
Try es_in.get() – user1827356 21 secs ago
add comment (requires an account with 50 reputation)

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.