aboutsummaryrefslogtreecommitdiffstats
path: root/examples/external/pandas
diff options
context:
space:
mode:
Diffstat (limited to 'examples/external/pandas')
-rw-r--r--examples/external/pandas/dataframe_model.py82
-rw-r--r--examples/external/pandas/doc/pandas.rst9
-rw-r--r--examples/external/pandas/doc/pandas_simple.pngbin0 -> 37161 bytes
-rw-r--r--examples/external/pandas/iris.csv151
-rw-r--r--examples/external/pandas/pandas.pyproject3
-rw-r--r--examples/external/pandas/requirements.txt1
6 files changed, 246 insertions, 0 deletions
diff --git a/examples/external/pandas/dataframe_model.py b/examples/external/pandas/dataframe_model.py
new file mode 100644
index 000000000..b3d9e81fe
--- /dev/null
+++ b/examples/external/pandas/dataframe_model.py
@@ -0,0 +1,82 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import pandas as pd
+
+from PySide6.QtWidgets import QTableView, QApplication
+from PySide6.QtCore import QAbstractTableModel, Qt, QModelIndex
+import sys
+
+
+class PandasModel(QAbstractTableModel):
+ """A model to interface a Qt view with pandas dataframe """
+
+ def __init__(self, dataframe: pd.DataFrame, parent=None):
+ QAbstractTableModel.__init__(self, parent)
+ self._dataframe = dataframe
+
+ def rowCount(self, parent=QModelIndex()) -> int:
+ """ Override method from QAbstractTableModel
+
+ Return row count of the pandas DataFrame
+ """
+ if parent == QModelIndex():
+ return len(self._dataframe)
+
+ return 0
+
+ def columnCount(self, parent=QModelIndex()) -> int:
+ """Override method from QAbstractTableModel
+
+ Return column count of the pandas DataFrame
+ """
+ if parent == QModelIndex():
+ return len(self._dataframe.columns)
+ return 0
+
+ def data(self, index: QModelIndex, role=Qt.ItemDataRole):
+ """Override method from QAbstractTableModel
+
+ Return data cell from the pandas DataFrame
+ """
+ if not index.isValid():
+ return None
+
+ if role == Qt.DisplayRole:
+ return str(self._dataframe.iloc[index.row(), index.column()])
+
+ return None
+
+ def headerData(
+ self, section: int, orientation: Qt.Orientation, role: Qt.ItemDataRole
+ ):
+ """Override method from QAbstractTableModel
+
+ Return dataframe index as vertical header data and columns as horizontal header data.
+ """
+ if role == Qt.DisplayRole:
+ if orientation == Qt.Horizontal:
+ return str(self._dataframe.columns[section])
+
+ if orientation == Qt.Vertical:
+ return str(self._dataframe.index[section])
+
+ return None
+
+
+if __name__ == "__main__":
+
+ app = QApplication(sys.argv)
+
+ df = pd.read_csv("iris.csv")
+
+ view = QTableView()
+ view.resize(800, 500)
+ view.horizontalHeader().setStretchLastSection(True)
+ view.setAlternatingRowColors(True)
+ view.setSelectionBehavior(QTableView.SelectRows)
+
+ model = PandasModel(df)
+ view.setModel(model)
+ view.show()
+ app.exec()
diff --git a/examples/external/pandas/doc/pandas.rst b/examples/external/pandas/doc/pandas.rst
new file mode 100644
index 000000000..8e75eead4
--- /dev/null
+++ b/examples/external/pandas/doc/pandas.rst
@@ -0,0 +1,9 @@
+Pandas Simple Example
+=====================
+
+A Python application that demonstrates how to visualize
+a Pandas DataFrame.
+
+.. image:: pandas_simple.png
+ :width: 400
+ :alt: Pandas Simple Screenshot
diff --git a/examples/external/pandas/doc/pandas_simple.png b/examples/external/pandas/doc/pandas_simple.png
new file mode 100644
index 000000000..ea5d240bd
--- /dev/null
+++ b/examples/external/pandas/doc/pandas_simple.png
Binary files differ
diff --git a/examples/external/pandas/iris.csv b/examples/external/pandas/iris.csv
new file mode 100644
index 000000000..bf14e161b
--- /dev/null
+++ b/examples/external/pandas/iris.csv
@@ -0,0 +1,151 @@
+"sepal.length","sepal.width","petal.length","petal.width","variety"
+5.1,3.5,1.4,.2,"Setosa"
+4.9,3,1.4,.2,"Setosa"
+4.7,3.2,1.3,.2,"Setosa"
+4.6,3.1,1.5,.2,"Setosa"
+5,3.6,1.4,.2,"Setosa"
+5.4,3.9,1.7,.4,"Setosa"
+4.6,3.4,1.4,.3,"Setosa"
+5,3.4,1.5,.2,"Setosa"
+4.4,2.9,1.4,.2,"Setosa"
+4.9,3.1,1.5,.1,"Setosa"
+5.4,3.7,1.5,.2,"Setosa"
+4.8,3.4,1.6,.2,"Setosa"
+4.8,3,1.4,.1,"Setosa"
+4.3,3,1.1,.1,"Setosa"
+5.8,4,1.2,.2,"Setosa"
+5.7,4.4,1.5,.4,"Setosa"
+5.4,3.9,1.3,.4,"Setosa"
+5.1,3.5,1.4,.3,"Setosa"
+5.7,3.8,1.7,.3,"Setosa"
+5.1,3.8,1.5,.3,"Setosa"
+5.4,3.4,1.7,.2,"Setosa"
+5.1,3.7,1.5,.4,"Setosa"
+4.6,3.6,1,.2,"Setosa"
+5.1,3.3,1.7,.5,"Setosa"
+4.8,3.4,1.9,.2,"Setosa"
+5,3,1.6,.2,"Setosa"
+5,3.4,1.6,.4,"Setosa"
+5.2,3.5,1.5,.2,"Setosa"
+5.2,3.4,1.4,.2,"Setosa"
+4.7,3.2,1.6,.2,"Setosa"
+4.8,3.1,1.6,.2,"Setosa"
+5.4,3.4,1.5,.4,"Setosa"
+5.2,4.1,1.5,.1,"Setosa"
+5.5,4.2,1.4,.2,"Setosa"
+4.9,3.1,1.5,.2,"Setosa"
+5,3.2,1.2,.2,"Setosa"
+5.5,3.5,1.3,.2,"Setosa"
+4.9,3.6,1.4,.1,"Setosa"
+4.4,3,1.3,.2,"Setosa"
+5.1,3.4,1.5,.2,"Setosa"
+5,3.5,1.3,.3,"Setosa"
+4.5,2.3,1.3,.3,"Setosa"
+4.4,3.2,1.3,.2,"Setosa"
+5,3.5,1.6,.6,"Setosa"
+5.1,3.8,1.9,.4,"Setosa"
+4.8,3,1.4,.3,"Setosa"
+5.1,3.8,1.6,.2,"Setosa"
+4.6,3.2,1.4,.2,"Setosa"
+5.3,3.7,1.5,.2,"Setosa"
+5,3.3,1.4,.2,"Setosa"
+7,3.2,4.7,1.4,"Versicolor"
+6.4,3.2,4.5,1.5,"Versicolor"
+6.9,3.1,4.9,1.5,"Versicolor"
+5.5,2.3,4,1.3,"Versicolor"
+6.5,2.8,4.6,1.5,"Versicolor"
+5.7,2.8,4.5,1.3,"Versicolor"
+6.3,3.3,4.7,1.6,"Versicolor"
+4.9,2.4,3.3,1,"Versicolor"
+6.6,2.9,4.6,1.3,"Versicolor"
+5.2,2.7,3.9,1.4,"Versicolor"
+5,2,3.5,1,"Versicolor"
+5.9,3,4.2,1.5,"Versicolor"
+6,2.2,4,1,"Versicolor"
+6.1,2.9,4.7,1.4,"Versicolor"
+5.6,2.9,3.6,1.3,"Versicolor"
+6.7,3.1,4.4,1.4,"Versicolor"
+5.6,3,4.5,1.5,"Versicolor"
+5.8,2.7,4.1,1,"Versicolor"
+6.2,2.2,4.5,1.5,"Versicolor"
+5.6,2.5,3.9,1.1,"Versicolor"
+5.9,3.2,4.8,1.8,"Versicolor"
+6.1,2.8,4,1.3,"Versicolor"
+6.3,2.5,4.9,1.5,"Versicolor"
+6.1,2.8,4.7,1.2,"Versicolor"
+6.4,2.9,4.3,1.3,"Versicolor"
+6.6,3,4.4,1.4,"Versicolor"
+6.8,2.8,4.8,1.4,"Versicolor"
+6.7,3,5,1.7,"Versicolor"
+6,2.9,4.5,1.5,"Versicolor"
+5.7,2.6,3.5,1,"Versicolor"
+5.5,2.4,3.8,1.1,"Versicolor"
+5.5,2.4,3.7,1,"Versicolor"
+5.8,2.7,3.9,1.2,"Versicolor"
+6,2.7,5.1,1.6,"Versicolor"
+5.4,3,4.5,1.5,"Versicolor"
+6,3.4,4.5,1.6,"Versicolor"
+6.7,3.1,4.7,1.5,"Versicolor"
+6.3,2.3,4.4,1.3,"Versicolor"
+5.6,3,4.1,1.3,"Versicolor"
+5.5,2.5,4,1.3,"Versicolor"
+5.5,2.6,4.4,1.2,"Versicolor"
+6.1,3,4.6,1.4,"Versicolor"
+5.8,2.6,4,1.2,"Versicolor"
+5,2.3,3.3,1,"Versicolor"
+5.6,2.7,4.2,1.3,"Versicolor"
+5.7,3,4.2,1.2,"Versicolor"
+5.7,2.9,4.2,1.3,"Versicolor"
+6.2,2.9,4.3,1.3,"Versicolor"
+5.1,2.5,3,1.1,"Versicolor"
+5.7,2.8,4.1,1.3,"Versicolor"
+6.3,3.3,6,2.5,"Virginica"
+5.8,2.7,5.1,1.9,"Virginica"
+7.1,3,5.9,2.1,"Virginica"
+6.3,2.9,5.6,1.8,"Virginica"
+6.5,3,5.8,2.2,"Virginica"
+7.6,3,6.6,2.1,"Virginica"
+4.9,2.5,4.5,1.7,"Virginica"
+7.3,2.9,6.3,1.8,"Virginica"
+6.7,2.5,5.8,1.8,"Virginica"
+7.2,3.6,6.1,2.5,"Virginica"
+6.5,3.2,5.1,2,"Virginica"
+6.4,2.7,5.3,1.9,"Virginica"
+6.8,3,5.5,2.1,"Virginica"
+5.7,2.5,5,2,"Virginica"
+5.8,2.8,5.1,2.4,"Virginica"
+6.4,3.2,5.3,2.3,"Virginica"
+6.5,3,5.5,1.8,"Virginica"
+7.7,3.8,6.7,2.2,"Virginica"
+7.7,2.6,6.9,2.3,"Virginica"
+6,2.2,5,1.5,"Virginica"
+6.9,3.2,5.7,2.3,"Virginica"
+5.6,2.8,4.9,2,"Virginica"
+7.7,2.8,6.7,2,"Virginica"
+6.3,2.7,4.9,1.8,"Virginica"
+6.7,3.3,5.7,2.1,"Virginica"
+7.2,3.2,6,1.8,"Virginica"
+6.2,2.8,4.8,1.8,"Virginica"
+6.1,3,4.9,1.8,"Virginica"
+6.4,2.8,5.6,2.1,"Virginica"
+7.2,3,5.8,1.6,"Virginica"
+7.4,2.8,6.1,1.9,"Virginica"
+7.9,3.8,6.4,2,"Virginica"
+6.4,2.8,5.6,2.2,"Virginica"
+6.3,2.8,5.1,1.5,"Virginica"
+6.1,2.6,5.6,1.4,"Virginica"
+7.7,3,6.1,2.3,"Virginica"
+6.3,3.4,5.6,2.4,"Virginica"
+6.4,3.1,5.5,1.8,"Virginica"
+6,3,4.8,1.8,"Virginica"
+6.9,3.1,5.4,2.1,"Virginica"
+6.7,3.1,5.6,2.4,"Virginica"
+6.9,3.1,5.1,2.3,"Virginica"
+5.8,2.7,5.1,1.9,"Virginica"
+6.8,3.2,5.9,2.3,"Virginica"
+6.7,3.3,5.7,2.5,"Virginica"
+6.7,3,5.2,2.3,"Virginica"
+6.3,2.5,5,1.9,"Virginica"
+6.5,3,5.2,2,"Virginica"
+6.2,3.4,5.4,2.3,"Virginica"
+5.9,3,5.1,1.8,"Virginica"
diff --git a/examples/external/pandas/pandas.pyproject b/examples/external/pandas/pandas.pyproject
new file mode 100644
index 000000000..4731cf7d9
--- /dev/null
+++ b/examples/external/pandas/pandas.pyproject
@@ -0,0 +1,3 @@
+{
+ "files": ["dataframe_model.py"]
+}
diff --git a/examples/external/pandas/requirements.txt b/examples/external/pandas/requirements.txt
new file mode 100644
index 000000000..fb6c7ed7e
--- /dev/null
+++ b/examples/external/pandas/requirements.txt
@@ -0,0 +1 @@
+pandas