-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DesignMatrixPanel to show DataFrame parameters in a table
- Loading branch information
Showing
2 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pandas as pd | ||
from qtpy.QtGui import QStandardItem, QStandardItemModel | ||
from qtpy.QtWidgets import QDialog, QTableView, QVBoxLayout | ||
|
||
|
||
class DesignMatrixPanel(QDialog): | ||
def __init__(self, design_matrix_df: pd.DataFrame, parent=None): | ||
super().__init__(parent) | ||
|
||
self.setWindowTitle("Design matrix parameters viewer") | ||
|
||
self.table_view = QTableView(self) | ||
self.table_view.setEditTriggers(QTableView.NoEditTriggers) | ||
|
||
self.model = self.create_model(design_matrix_df) | ||
self.table_view.setModel(self.model) | ||
|
||
# Layout to hold the table view | ||
layout = QVBoxLayout() | ||
layout.addWidget(self.table_view) | ||
self.setLayout(layout) | ||
|
||
@staticmethod | ||
def create_model(design_matrix_df: pd.DataFrame): | ||
# Create a model | ||
model = QStandardItemModel() | ||
model.setHorizontalHeaderLabels(design_matrix_df.columns.astype(str).tolist()) | ||
|
||
# Populate the model with data | ||
for index, _ in design_matrix_df.iterrows(): | ||
items = [ | ||
QStandardItem(str(design_matrix_df.at[index, col])) | ||
for col in design_matrix_df.columns | ||
] | ||
model.appendRow(items) | ||
return model |