0

l make an application to use pandas function. l want user to able to write down his own function to get whatever he wants. but l could not do and find proper option. l m new to code. so how can l convert entrybox input to variable? an example in red circle. it could be anyhting user write down such as df_la['RPM']==40 or else

enter image description here

here is some part of my code:

path = filedialog.askopenfilename(initialdir="D:\GIS\Python_Pro", title="Select a file", filetypes=(
        ("xlsx files", "*.xlsx"), ("xls files", "*.xlsx"), ("cvs files", "*.cvs"), ("All Files", "*.*")))
select_split = path.split("/")
excel_file = select_split[-1].split(".")
excel_name = excel_file[0]
df_la = pd.read_excel(path)
header_cols = list(df_la.columns)


def Where():
        a=df_la.where(e.get())
        print(a)
        lbl = Label(frm_btn, text="Where value of " + str() + " = " + str(a), bd=10, relief=SUNKEN,
                    bg="black", fg="white", font=("Ariel", "10", "bold"))
        lbl.grid(row=0, column=0, sticky="nsew", columnspan=24, rowspan=3, padx=10)


e=Entry(frm_btn,bd=2,relief=SUNKEN,fg="Blue",font=("Ariel","11","bold"),bg="light grey")
e.grid(row=5,column=3,sticky="nsew",columnspan=15,padx=5)

btn_where=Button(frm_btn,text="Search",bd=2,relief=FLAT,bg="Black",fg="White",font=("Ariel","10","bold"),command=Where)
btn_where.grid(row=6,column=0,sticky="nsew",padx=2,pady=2)
ömer sarı
  • 639
  • 1
  • 10
  • 30
  • Cant really understand what you are asking. You want to get the text of an entry and do what with it? – Jordan Mar 29 '20 at 18:46
  • l have dataframe (df_la) when user clıck to where button, where function will get input in entrybox and For example, in entrybox (df_la['RPM'] – ömer sarı Mar 29 '20 at 20:13

1 Answers1

0

firstly, thanks for an idea. l got from jizhihaoSAMA . so that adjustment works fine. exec() return none but eva() returns what l want.please find the adjustment below. l will check for another solutions could be better off.

def Where():
        c=eval('df_la.where({})'.format(e.get()))
        dfs=pd.DataFrame(c)
        print(dfs.notnull().sum())

        lbl = Label(frm_btn, text="Where value of " + str(c) + " = ", bd=10, relief=SUNKEN,
                    bg="black", fg="white", font=("Ariel", "10", "bold"))
        lbl.grid(row=0, column=0, sticky="nsew", columnspan=24, rowspan=3, padx=10)
ömer sarı
  • 639
  • 1
  • 10
  • 30
  • Yes,I find it.Use `exec()` and `eval()` are not good practice. So I have deleted my answer. – jizhihaoSAMA Mar 30 '20 at 12:08
  • thanks for tip as l m new and l was not aware of some parts. after your suggestion, https://stackoverflow.com/questions/2220699/whats-the-difference-between-eval-exec-and-compile. l check this question and it is explained really great – ömer sarı Mar 30 '20 at 12:11