first commit

This commit is contained in:
lennlouis 2024-06-08 03:00:08 +08:00
parent e99b3d4fb9
commit 0e74a969b1
11 changed files with 531 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.idea/
__pycache__/

263
MainWindow.ui Normal file
View File

@ -0,0 +1,263 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="lineEdit_filepath"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_filepath">
<property name="text">
<string>打开数据</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_filepath_clear">
<property name="text">
<string>清除</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_linear_regression">
<property name="text">
<string>线性回归</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Kmeans">
<property name="text">
<string>聚类算法</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="page">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QTableWidget" name="tableWidget_linear_regression"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Linear Regression</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="checkBox_linear_regression_data_cleaning">
<property name="text">
<string>数据清洗</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_linear_regression_normalize">
<property name="text">
<string>数据归一化</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_linear_regression_preview">
<property name="text">
<string>开始预处理</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QProgressBar" name="progressBar_linear_regression">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_linear_regression_original">
<property name="text">
<string>原始数据</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_linear_regression_original_col">
<property name="text">
<string>列</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_linear_regression_target">
<property name="text">
<string>目标数据</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit_linear_regression_target"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_linear_regression_target_col">
<property name="text">
<string>列</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="pushButton_linear_regression_begin">
<property name="text">
<string>开始拟合</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_linear_regression_save">
<property name="text">
<string>保存数据</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_linear_regression_show">
<property name="text">
<string>显示结果</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2"/>
<widget class="QWidget" name="page_3"/>
<widget class="QWidget" name="page_4"/>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>24</height>
</rect>
</property>
<widget class="QMenu" name="menu_file">
<property name="title">
<string>文件</string>
</property>
<addaction name="actionOpen"/>
<addaction name="actionClear"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menu_about">
<property name="title">
<string>关于</string>
</property>
<addaction name="actionAbout_At"/>
<addaction name="actionAbout"/>
</widget>
<addaction name="menu_file"/>
<addaction name="menu_about"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionOpen">
<property name="text">
<string>Open</string>
</property>
</action>
<action name="actionClear">
<property name="text">
<string>Clear</string>
</property>
</action>
<action name="actionAbout_At">
<property name="text">
<string>About At</string>
</property>
</action>
<action name="actionAbout">
<property name="text">
<string>About</string>
</property>
</action>
<action name="actionExit">
<property name="text">
<string>Exit</string>
</property>
</action>
</widget>
<resources>
<include location="images.qrc"/>
</resources>
<connections/>
</ui>

43
MainWindows.py Normal file
View File

@ -0,0 +1,43 @@
import Ui_MainWindow
from PyQt5.QtCore import QFile, QFileInfo, pyqtSlot, pyqtSignal
from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtGui import QIcon, QPixmap
from data_set_read import Data_Read
class MainWindows:
def __init__(self) -> None:
self.MainWindow = QtWidgets.QMainWindow()
self.ui = Ui_MainWindow.Ui_MainWindow()
self.ui.setupUi(self.MainWindow)
self.window_ui_init()
self.file_object_init()
def window_ui_init(self):
self.MainWindow.setWindowTitle("Data Analysis By Python")
self.MainWindow.setWindowIcon(QIcon(QPixmap(":/src/image/icon.jpg")))
self.ui.progressBar_linear_regression.setValue(0)
def file_object_init(self):
self.ui.pushButton_filepath.clicked.connect(self.pushButton_filepath_clicked)
self.ui.pushButton_filepath_clear.clicked.connect(self.pushButton_filepath_clear_clicked)
self.ui.pushButton_linear_regression.clicked.connect(lambda checked: self.ui.stackedWidget.setCurrentIndex(0))
self.ui.pushButton_Kmeans.clicked.connect(lambda checked: self.ui.stackedWidget.setCurrentIndex(1))
def pushButton_filepath_clicked(self):
file_path = QtWidgets.QFileDialog.getOpenFileName(self.MainWindow, "Open File", ".", "All Files(*);;csv Files(*.csv);;Old Excel Files(*.xls);;New Excel Files(*.xlsx)")
print(file_path[0])
info = QFileInfo(file_path[0])
suffix = info.suffix()
if suffix == "csv":
#self.data_read = Data_Read(file_path[0], suffix)
self.ui.lineEdit_filepath.setText(file_path[0])
elif suffix == "xls" or suffix == "xlsx":
#self.data_read = Data_Read(file_path[0], suffix)
self.ui.lineEdit_filepath.setText(file_path[0])
# if file_path is not None:
# self.ui.lineEdit_filepath.setText(file_path)
def pushButton_filepath_clear_clicked(self):
self.ui.lineEdit_filepath.clear()

192
Ui_MainWindow.py Normal file
View File

@ -0,0 +1,192 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/Users/lennlouis/lenn_ws/python_ws/pyqt_data_analysis/MainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.lineEdit_filepath = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_filepath.setObjectName("lineEdit_filepath")
self.horizontalLayout.addWidget(self.lineEdit_filepath)
self.pushButton_filepath = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_filepath.setObjectName("pushButton_filepath")
self.horizontalLayout.addWidget(self.pushButton_filepath)
self.pushButton_filepath_clear = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_filepath_clear.setObjectName("pushButton_filepath_clear")
self.horizontalLayout.addWidget(self.pushButton_filepath_clear)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setObjectName("widget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.widget)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.pushButton_linear_regression = QtWidgets.QPushButton(self.widget)
self.pushButton_linear_regression.setObjectName("pushButton_linear_regression")
self.horizontalLayout_2.addWidget(self.pushButton_linear_regression)
self.pushButton_Kmeans = QtWidgets.QPushButton(self.widget)
self.pushButton_Kmeans.setObjectName("pushButton_Kmeans")
self.horizontalLayout_2.addWidget(self.pushButton_Kmeans)
self.pushButton_4 = QtWidgets.QPushButton(self.widget)
self.pushButton_4.setObjectName("pushButton_4")
self.horizontalLayout_2.addWidget(self.pushButton_4)
self.pushButton_5 = QtWidgets.QPushButton(self.widget)
self.pushButton_5.setObjectName("pushButton_5")
self.horizontalLayout_2.addWidget(self.pushButton_5)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.stackedWidget = QtWidgets.QStackedWidget(self.widget)
self.stackedWidget.setObjectName("stackedWidget")
self.page = QtWidgets.QWidget()
self.page.setObjectName("page")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.page)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.tableWidget_linear_regression = QtWidgets.QTableWidget(self.page)
self.tableWidget_linear_regression.setObjectName("tableWidget_linear_regression")
self.tableWidget_linear_regression.setColumnCount(0)
self.tableWidget_linear_regression.setRowCount(0)
self.horizontalLayout_5.addWidget(self.tableWidget_linear_regression)
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.label = QtWidgets.QLabel(self.page)
self.label.setObjectName("label")
self.verticalLayout_3.addWidget(self.label)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setSpacing(0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.checkBox_linear_regression_data_cleaning = QtWidgets.QCheckBox(self.page)
self.checkBox_linear_regression_data_cleaning.setObjectName("checkBox_linear_regression_data_cleaning")
self.horizontalLayout_3.addWidget(self.checkBox_linear_regression_data_cleaning)
self.checkBox_linear_regression_normalize = QtWidgets.QCheckBox(self.page)
self.checkBox_linear_regression_normalize.setObjectName("checkBox_linear_regression_normalize")
self.horizontalLayout_3.addWidget(self.checkBox_linear_regression_normalize)
self.pushButton_linear_regression_preview = QtWidgets.QPushButton(self.page)
self.pushButton_linear_regression_preview.setObjectName("pushButton_linear_regression_preview")
self.horizontalLayout_3.addWidget(self.pushButton_linear_regression_preview)
self.verticalLayout_3.addLayout(self.horizontalLayout_3)
self.progressBar_linear_regression = QtWidgets.QProgressBar(self.page)
self.progressBar_linear_regression.setProperty("value", 24)
self.progressBar_linear_regression.setObjectName("progressBar_linear_regression")
self.verticalLayout_3.addWidget(self.progressBar_linear_regression)
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.setObjectName("gridLayout")
self.label_linear_regression_original = QtWidgets.QLabel(self.page)
self.label_linear_regression_original.setObjectName("label_linear_regression_original")
self.gridLayout.addWidget(self.label_linear_regression_original, 0, 0, 1, 1)
self.lineEdit = QtWidgets.QLineEdit(self.page)
self.lineEdit.setObjectName("lineEdit")
self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1)
self.label_linear_regression_original_col = QtWidgets.QLabel(self.page)
self.label_linear_regression_original_col.setObjectName("label_linear_regression_original_col")
self.gridLayout.addWidget(self.label_linear_regression_original_col, 0, 2, 1, 1)
self.label_linear_regression_target = QtWidgets.QLabel(self.page)
self.label_linear_regression_target.setObjectName("label_linear_regression_target")
self.gridLayout.addWidget(self.label_linear_regression_target, 1, 0, 1, 1)
self.lineEdit_linear_regression_target = QtWidgets.QLineEdit(self.page)
self.lineEdit_linear_regression_target.setObjectName("lineEdit_linear_regression_target")
self.gridLayout.addWidget(self.lineEdit_linear_regression_target, 1, 1, 1, 1)
self.label_linear_regression_target_col = QtWidgets.QLabel(self.page)
self.label_linear_regression_target_col.setObjectName("label_linear_regression_target_col")
self.gridLayout.addWidget(self.label_linear_regression_target_col, 1, 2, 1, 1)
self.verticalLayout_3.addLayout(self.gridLayout)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.pushButton_linear_regression_begin = QtWidgets.QPushButton(self.page)
self.pushButton_linear_regression_begin.setObjectName("pushButton_linear_regression_begin")
self.horizontalLayout_4.addWidget(self.pushButton_linear_regression_begin)
self.pushButton_linear_regression_save = QtWidgets.QPushButton(self.page)
self.pushButton_linear_regression_save.setObjectName("pushButton_linear_regression_save")
self.horizontalLayout_4.addWidget(self.pushButton_linear_regression_save)
self.pushButton_linear_regression_show = QtWidgets.QPushButton(self.page)
self.pushButton_linear_regression_show.setObjectName("pushButton_linear_regression_show")
self.horizontalLayout_4.addWidget(self.pushButton_linear_regression_show)
self.verticalLayout_3.addLayout(self.horizontalLayout_4)
self.horizontalLayout_5.addLayout(self.verticalLayout_3)
self.stackedWidget.addWidget(self.page)
self.page_2 = QtWidgets.QWidget()
self.page_2.setObjectName("page_2")
self.stackedWidget.addWidget(self.page_2)
self.page_3 = QtWidgets.QWidget()
self.page_3.setObjectName("page_3")
self.stackedWidget.addWidget(self.page_3)
self.page_4 = QtWidgets.QWidget()
self.page_4.setObjectName("page_4")
self.stackedWidget.addWidget(self.page_4)
self.verticalLayout.addWidget(self.stackedWidget)
self.verticalLayout_2.addWidget(self.widget)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 24))
self.menubar.setObjectName("menubar")
self.menu_file = QtWidgets.QMenu(self.menubar)
self.menu_file.setObjectName("menu_file")
self.menu_about = QtWidgets.QMenu(self.menubar)
self.menu_about.setObjectName("menu_about")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionOpen = QtWidgets.QAction(MainWindow)
self.actionOpen.setObjectName("actionOpen")
self.actionClear = QtWidgets.QAction(MainWindow)
self.actionClear.setObjectName("actionClear")
self.actionAbout_At = QtWidgets.QAction(MainWindow)
self.actionAbout_At.setObjectName("actionAbout_At")
self.actionAbout = QtWidgets.QAction(MainWindow)
self.actionAbout.setObjectName("actionAbout")
self.actionExit = QtWidgets.QAction(MainWindow)
self.actionExit.setObjectName("actionExit")
self.menu_file.addAction(self.actionOpen)
self.menu_file.addAction(self.actionClear)
self.menu_file.addAction(self.actionExit)
self.menu_about.addAction(self.actionAbout_At)
self.menu_about.addAction(self.actionAbout)
self.menubar.addAction(self.menu_file.menuAction())
self.menubar.addAction(self.menu_about.menuAction())
self.retranslateUi(MainWindow)
self.stackedWidget.setCurrentIndex(1)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton_filepath.setText(_translate("MainWindow", "打开数据"))
self.pushButton_filepath_clear.setText(_translate("MainWindow", "清除"))
self.pushButton_linear_regression.setText(_translate("MainWindow", "线性回归"))
self.pushButton_Kmeans.setText(_translate("MainWindow", "聚类算法"))
self.pushButton_4.setText(_translate("MainWindow", "PushButton"))
self.pushButton_5.setText(_translate("MainWindow", "PushButton"))
self.label.setText(_translate("MainWindow", "Linear Regression"))
self.checkBox_linear_regression_data_cleaning.setText(_translate("MainWindow", "数据清洗"))
self.checkBox_linear_regression_normalize.setText(_translate("MainWindow", "数据归一化"))
self.pushButton_linear_regression_preview.setText(_translate("MainWindow", "开始预处理"))
self.label_linear_regression_original.setText(_translate("MainWindow", "原始数据"))
self.label_linear_regression_original_col.setText(_translate("MainWindow", ""))
self.label_linear_regression_target.setText(_translate("MainWindow", "目标数据"))
self.label_linear_regression_target_col.setText(_translate("MainWindow", ""))
self.pushButton_linear_regression_begin.setText(_translate("MainWindow", "开始拟合"))
self.pushButton_linear_regression_save.setText(_translate("MainWindow", "保存数据"))
self.pushButton_linear_regression_show.setText(_translate("MainWindow", "显示结果"))
self.menu_file.setTitle(_translate("MainWindow", "文件"))
self.menu_about.setTitle(_translate("MainWindow", "关于"))
self.actionOpen.setText(_translate("MainWindow", "Open"))
self.actionClear.setText(_translate("MainWindow", "Clear"))
self.actionAbout_At.setText(_translate("MainWindow", "About At"))
self.actionAbout.setText(_translate("MainWindow", "About"))
self.actionExit.setText(_translate("MainWindow", "Exit"))

0
data.csv Normal file
View File

View File

@ -0,0 +1,16 @@
import pandas as pd
import numpy as np
class Data_Read:
def __init__(self, file_path, suffix) -> None:
self.file_path = file_path
if suffix == "csv":
self.data_frame = pd.read_csv(self.file_path)
elif suffix == "xls" or suffix == "xlsx":
self.data_frame = pd.read_excel(self.file_path)
def get_head_data(self, n : int):
return self.data_frame.head(n)

5
images.qrc Normal file
View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>src/image/icon.jpg</file>
</qresource>
</RCC>

10
main.py
View File

@ -0,0 +1,10 @@
from MainWindows import MainWindows
from PyQt5.QtCore import QFile, QFileInfo
from PyQt5 import QtGui, QtWidgets, QtCore
import sys
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainwindows = MainWindows()
mainwindows.MainWindow.show()
sys.exit(app.exec_())

BIN
src/.DS_Store vendored Normal file

Binary file not shown.

BIN
src/image/icon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB