Reputation: 739
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
Upvotes: 10
Views: 14144
Reputation: 109
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
Upvotes: 1
Reputation: 739
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).
Upvotes: 1