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:
I know they are missed typed -- are there convenient hacks around this?
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__'
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>