Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to show interactive table with python (columns adjustably by user)

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

like image 648
Declan Avatar asked Aug 20 '18 16:08

Declan


1 Answers

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).

like image 127
Declan Avatar answered Nov 04 '22 00:11

Declan