10

What are some good options to show a nice interactive table (2d) with python3? Id like the user to be able to sort the rowns (eg by clicking a column header), show/hide columns etc.

Ideally without having to use (undebuggable) jupyter notebooks.

If Im not incorrect it seems a lot easier to do this with jupyter notebooks than with "regular" python. Why is this?

Calling something like pandas.head() automatically displays a proper gui if you set %matplotlib inline ?

Thanks in advance

Declan
  • 669
  • 1
  • 7
  • 12
  • 1
    You're asking about making a GUI to display some data? Easiest way would be ```Tkinter Treeview``` – Joshua Nixon Aug 20 '18 at 16:47
  • 1
    you can debug with the `%debug` command in a jupyter notebook after an exception has been raised; have you considered using `ipywidgets.interact` to get the behavior you describe? – jeschwar Aug 20 '18 at 16:50
  • 1
    If you use Spyde IDE you can open good GUI interface by double clicking on variable in Variable Explorer section – Sergei Aug 20 '18 at 17:43
  • 1
    Check `table` element from `PyQT`. I think that's what you're looking for. – Alex Aug 20 '18 at 18:34
  • https://pythonspot.com/pyqt5-table/ together with adding the line *self.tableWidget.setSortingEnabled(True)*, (which enables sorting based on the column the user clicks on) seems to provide the best starting point (if one wants to avoid being tied to jupyter notebooks at least) PySide2 (http://blog.qt.io/blog/category/qt-for-python/) from Qt im sure would be a good option too but its not documented well (yet), and Tkinter seems to be quite difficult to install – Declan Aug 21 '18 at 14:23

2 Answers2

1

Using a table widget as described at pythonspot above, requires individually adding each row of data, via the creation and insertion of individual QTableWidgetItems. eg

  self.tableWidget.setItem(0, 0, QTableWidgetItem("Cell (1,1)"))

This may be sufficient in some cases but it doesnt generalize so well.

PandasTableView is a more MVC orientated approach that instead uses a a QTableView and an associated Model (QAbstractTableModel) class (to supply the data at runtime eg after reading a cvs file). Its mentioned at stackoverflow and the complete code can be found at github

Though requiring more code and being somewhat more difficult to understand, its the most flexible, and pretty much what I as looking for. Not least of all because it shows how to incoroporate data from a pandas dataframe.

There are various solutions (eg QGrid) that only work exclusively in Jupyter notebooks (presumably behind the scenes they make use of html tables etc, which is why they require the browser/notebook environment).

Declan
  • 669
  • 1
  • 7
  • 12
0

You can use plotly or if you are interested in more interactivity, go for Dash DataTable:

The DataTable is interactive. This chapter demonstrates the interactive features of the table and how to wire up these interations to Python callbacks. These actions include:

  • Paging
  • Selecting Rows
  • Sorting Columns
  • Filtering Data
SNA
  • 99
  • 9