Python / Pandas - 用于查看DataFrame或Matrix的GUI [英] Python / Pandas - GUI for viewing a DataFrame or Matrix

查看:2783
本文介绍了Python / Pandas - 用于查看DataFrame或Matrix的GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Pandas包,它创建一个DataFrame对象,它基本上是一个标记的矩阵。通常我有一些列有长字符串或数据框的列,因此简单的打印命令不能正常工作。我已经写了一些文本输出功能,但并不是很好。



我真正喜欢的是一个简单的GUI,让我可以与数据框/矩阵进行交互/表。就像你在SQL工具中找到的。基本上是一个具有只读电子表格,如查看数据的窗口。我可以通过长桌子等来扩展列,上下翻页。



我会怀疑这样的东西存在,但是我必须使用错误的词语。如果它是大熊猫特定的,那将是巨大的,但我猜想我可以使用任何矩阵接受工具。 (BTW - 我在Windows上)



任何指针?



或者反过来说,如果有人知道这个空间很好,知道这可能不存在,任何建议如果有一个简单的GUI框架/小部件我可以用来滚动我自己的? (但是由于我的需求有限,我不愿意学习一个大的GUI框架,并为这一块做一堆编码。)

解决方案

我使用PyQt中的 QTableWidget 显示一个 DataFrame 。我创建一个 QTableWidgetObject ,然后使用 DataFrame QTableWidgetItems >值。
以下是读取CSV文件的代码片段,创建一个 DataFrame ,然后显示在GUI中:

  df = read_csv(filename,index_col = 0,header = 0)
self.datatable = QtGui.QTableWidget(parent = self)
self.datatable .setColumnCount(len(df.columns))
self.datatable.setRowCount(len(df.index))
for i in range(len(df.index)):
for j在范围内(len(df.columns)):
self.datatable.setItem(i,j,QtGui.QTableWidgetItem(str(df.iget_value(i,j))))


I'm using the Pandas package and it creates a DataFrame object, which is basically a labeled matrix. Often I have columns that have long string fields, or dataframes with many columns, so the simple print command doesn't work well. I've written some text output functions, but they aren't great.

What I'd really love is a simple GUI that lets me interact with a dataframe / matrix / table. Just like you would find in a SQL tool. Basically a window that has a read-only spreadsheet like view into the data. I can expand columns, page up and down through long tables, etc.

I would suspect something like this exists, but I must be Googling with the wrong terms. It would be great if it is pandas specific, but I would guess I could use any matrix-accepting tool. (BTW - I'm on Windows.)

Any pointers?

Or, conversely, if someone knows this space well and knows this probably doesn't exist, any suggestions on if there is a simple GUI framework / widget I could use to roll my own? (But since my needs are limited, I'm reluctant to have to learn a big GUI framework and do a bunch of coding for this one piece.)

解决方案

I use QTableWidget from PyQt to display a DataFrame. I create a QTableWidgetObject and then populate with QTableWidgetItems created with DataFrame values. Following is the snippet of code that reads a CSV file ,create a DataFrame, then display in a GUI:

df  = read_csv(filename, index_col = 0,header = 0)
self.datatable = QtGui.QTableWidget(parent=self)
self.datatable.setColumnCount(len(df.columns))
self.datatable.setRowCount(len(df.index))
for i in range(len(df.index)):
    for j in range(len(df.columns)):
        self.datatable.setItem(i,j,QtGui.QTableWidgetItem(str(df.iget_value(i, j))))

这篇关于Python / Pandas - 用于查看DataFrame或Matrix的GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆