-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPyqt5vePandasileCsv.py
49 lines (38 loc) · 1.54 KB
/
Pyqt5vePandasileCsv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
) ( (
( /( )\ ) )\ ( ) ) (
)\()) ((_) ( /( ((_) )\ ) ( /( ( ( /( )(
((_)\ _ )(_)) _ (()/( )(_)) )\ )(_)) (()\
| |(_) | | ((_)_ | | )(_)) ((_)_ ((_) ((_)_ ((_)
| '_ \ | | / _` | | | | || | / _` | (_-< / _` | | '_|
|_.__/ |_| \__,_| |_| \_, | \__,_| /__/ \__,_| |_|
|__/
"""
import sys
import pandas as pd
from PyQt5.QtWidgets import QApplication, QTableView
from PyQt5.QtCore import QAbstractTableModel, Qt
df = pd.read_excel(".../gdp_per_capita_2017.xlsx")
print(df)
class pandasModel(QAbstractTableModel):def __init__(self, data):
QAbstractTableModel.__init__(self)
self._data = datadef rowCount(self, parent=None):
return self._data.shape[0]def columnCount(self, parnet=None):
return self._data.shape[1]
def data(self, index, role=Qt.DisplayRole):
if index.isValid():
if role == Qt.DisplayRole:
return str(self._data.iloc[index.row(), index.column()])
return Nonedef headerData(self, col, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return self._data.columns[col]
return None
if __name__ == '__main__':
app = QApplication(sys.argv)
model = pandasModel(df)
view = QTableView()
view.setModel(model)
view.resize(770, 800)
#view.showMaximized()
view.show()
sys.exit(app.exec_())