如何在GUI中使用Tkinter在python中显示经过过滤的DataFrame?

问题描述

正如标题所示,我需要在GUI(使用Tkinter)中制作一个按钮,向我显示已过滤的DataFrame

数据框的导入

df = pd.read_csv (r'C:\Users\shold\Downloads\df.csv')
df = df[['A','B','C','D','E','F','G']]

已过滤的DataFrame

FIltered_df= df.drop_duplicates(subset=['G'])
FIltered_df= FIltered_df.iloc[:,[0,6]]

我试图创建一个GUI,但是当我运行代码时,打印功能是在我的IDE(Jupyter)中而不是在GUI上运行:我该如何解决这个问题?这个想法是在现有的600x600窗口中创建一个新窗口或一个列表,其中显示所有过滤的结果。

window = tk.Tk()
window.geometry("600x600")
window.title("GUI")
def first_print():
    text ="Filter the df"
    text_output = tk.Label(window,text=text)
    text_output.grid(row=0,column=1,padx = 50)
    print(FIltered_df)
    
first_button = tk.Button(text="Filter the df",command=first_print)
first_button.grid(row=0,column=0)

谢谢

解决方法

尝试一下。要在GUI中显示内容,您必须使用类似{-# LANGUAGE AllowAmbiguousTypes,TypeApplications,ScopedTypeVariables #-} data BestConstraint a where BCOrd :: Ord a => BestConstraint a BCEq :: Eq a => BestConstraint a BCNone :: BestConstraint a class BC a where bestC :: BestConstraint a instance BC Int where bestC = BCOrd -- ... etc. instance BC a => BC [a] where bestC = case bestC @a of BCOrd -> BCOrd BCEq -> BCEq BCNone -> BCNone prob :: forall a . BestConstraint a => [(a,Rational)] -> Prob a prob xs = case bestC @a of BCOrd -> POrd .... -- build the tree BCEq -> PEq xs BCNone -> PPlain xs 的内容。

对功能进行这些更改。

Label

希望它消除了您的疑问。

欢呼

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...