首页 > 解决方案 > 从 DataFrame 填充 wxPython Grid

问题描述

我正在构建一个 GUI 来查看和更新​​ mySQL 中的表。我正在获取结果,将它们加载到 Pandas DataFrame 中,然后将它们写到网格中。

从 mySQL 到 DataFrame,几乎是即时的。问题是循环每个值并将它们写入网格需要一些时间。我正在尝试找到一种更快的方法来填充网格。我已经研究过使用 GridTableBase 类,但我并没有真正理解它,因为我对 Python 不是很有经验。

要加载 DataFrame,我正在使用:

db_con = MySQLdb.connect(user=user_id,password=pw,database=db_name,host=host_id,charset='utf8')
cursor = db_con.cursor()

填充 wxPython 网格:(由于某种原因,这会在同一张表上引发错误)

#Populate Grid
for i in range(len(self.df_data.index)):
    for j in range(len(self.df_data.columns)):
         self.data_grid.SetCellValue(i,j,self.df_data.iat[i,j])

UPDATE: I have used the GridTableBase. The result is not much faster

标签: pythonpandaswxpython

解决方案


推荐阅读