在好例子网,分享、交流、成长!
您当前所在位置:首页Python 开发实例Python语言基础 → python数据分析与处理

python数据分析与处理

Python语言基础

下载此实例
  • 开发语言:Python
  • 实例大小:9.84KB
  • 下载次数:84
  • 浏览次数:780
  • 发布时间:2020-05-13
  • 实例类别:Python语言基础
  • 发 布 人:这里的黎明静悄悄
  • 文件格式:.py
  • 所需积分:2
 相关标签: 数据分析 分析 数据

实例介绍

【实例简介】python数据分析处理,筛选再生成excel。
【实例截图】from clipboard
【核心代码】
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import * from PyQt5.QtCore import * import pandas as pd import numpy as np from tkinter import messagebox import win32api,win32con from tkinter import * class Ui_MainWindow(QMainWindow): def __init__(self): super(QtWidgets.QMainWindow,self).__init__() self.setupUi(self) self.retranslateUi(self) def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(666, 680) self.centralWidget = QtWidgets.QWidget(MainWindow) self.centralWidget.setObjectName("centralWidget") self.retranslateUi(MainWindow) self.tableWidget = QtWidgets.QTableWidget(self.centralWidget) self.tableWidget.setGeometry(QtCore.QRect(0, 60, 813, 371)) self.tableWidget.setObjectName("tableWidget") self.tableWidget.setColumnCount(0) self.tableWidget.setRowCount(0) self.tableWidget.setStyleSheet("selection-background-color:pink") self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers) self.tableWidget.raise_() # self.tableWidget_1 = QtWidgets.QTableWidget(self.centralWidget_1)  # self.tableWidget_1.setGeometry(QtCore.QRect(0, 450, 813, 200))  # self.tableWidget_1.setObjectName("tableWidget")  # self.tableWidget_1.setColumnCount(0)  # self.tableWidget_1.setRowCount(0)  # self.tableWidget_1.setStyleSheet("selection-background-color:pink")  # self.tableWidget_1.setEditTriggers(QAbstractItemView.NoEditTriggers)  # self.tableWidget_1.raise_()   self.pushButton = QtWidgets.QPushButton(self.centralWidget) self.pushButton.setGeometry(QtCore.QRect(20, 20, 75, 23)) self.pushButton.setObjectName("pushButton") self.pushButton.setText("打开") self.pushButton_1 = QtWidgets.QPushButton(self.centralWidget) self.pushButton_1.setGeometry(QtCore.QRect(100, 20, 130, 23)) self.pushButton_1.setObjectName("pushButton") self.pushButton_1.setText("筛选31个周期数据") self.pushButton_2 = QtWidgets.QPushButton(self.centralWidget) self.pushButton_2.setGeometry(QtCore.QRect(230, 20, 130, 23)) self.pushButton_2.setObjectName("pushButton") self.pushButton_2.setText("拟合求极化参数") self.pushButton_3 = QtWidgets.QPushButton(self.centralWidget) self.pushButton_3.setGeometry(QtCore.QRect(360, 20, 130, 23)) self.pushButton_3.setObjectName("pushButton") self.pushButton_3.setText("极化参数拟合")

        MainWindow.setCentralWidget(self.centralWidget)
        QtCore.QMetaObject.connectSlotsByName(MainWindow) self.pushButton.clicked.connect(self.openfile) self.pushButton.clicked.connect(self.creat_table_show) self.pushButton_1.clicked.connect(self.select_31) self.pushButton_1.clicked.connect(self.select_31_table_show) def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "BMS数据预处理")) def openfile(self): ###获取路径===================================================================   openfile_name = QFileDialog.getOpenFileName(self,'选择文件','','Excel files(*.xlsx , *.xls)') #print(openfile_name)  global path_openfile_name global data global b global s ###获取路径====================================================================   path_openfile_name = openfile_name[0] def creat_table_show(self): ###===========读取表格,转换表格,===========================================  if len(path_openfile_name) > 0: #     ##===========读取表格,转换表格,===========================================  #     data = pd.read_excel(path_openfile_name)  #     Adata = pd.DataFrame(data)  #     Bdata = Adata[Adata['x'] == 0]  #     cycle = int(len(Bdata) / 11)  #     Cdata = {}  #  #     for i in range(cycle):  #         b = Bdata.loc[i * 14   4:i * 14   9]  #     b.to_excel('C:\\Users\\xyy\\Desktop\\119.xlsx')  #  #     input_table = b   input_table = pd.read_excel(path_openfile_name) #print(input_table)  input_table_rows = input_table.shape[0]
            input_table_colunms = input_table.shape[1] #print(input_table_rows)  #print(input_table_colunms)  input_table_header = input_table.columns.values.tolist() #print(input_table_header)   ###===========读取表格,转换表格,============================================  ###======================给tablewidget设置行列表头============================   self.tableWidget.setColumnCount(input_table_colunms) self.tableWidget.setRowCount(input_table_rows) self.tableWidget.setHorizontalHeaderLabels(input_table_header) ###======================给tablewidget设置行列表头============================   ###================遍历表格每个元素,同时添加到tablewidget中========================  for i in range(input_table_rows):
                input_table_rows_values = input_table.iloc[[i]] #print(input_table_rows_values)  input_table_rows_values_array = np.array(input_table_rows_values)
                input_table_rows_values_list = input_table_rows_values_array.tolist()[0] #print(input_table_rows_values_list)  for j in range(input_table_colunms):
                    input_table_items_list = input_table_rows_values_list[j] #print(input_table_items_list)  # print(type(input_table_items_list))   ###==============将遍历的元素添加到tablewidget中并显示=======================   input_table_items = str(input_table_items_list)
                    newItem = QTableWidgetItem(input_table_items)
                    newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter) self.tableWidget.setItem(i, j, newItem) ###================遍历表格每个元素,同时添加到tablewidget中========================  else: self.centralWidget.show() def select_31(self): ###===========读取表格,转换表格,===========================================  data = pd.read_excel(path_openfile_name)
        Adata = pd.DataFrame(data)
        Bdata = Adata[Adata['x'] == 0]
        cycle = int(len(Bdata) / 11) Cdata = {} for i in range(cycle):
            b = Bdata.loc[i * 14   4:i * 14   9]
        b.to_excel('C:\\Users\\xyy\\Desktop\\150.xlsx') def select_31_table_show(self): if len(pd.read_excel('C:\\Users\\xyy\\Desktop\\150.xlsx'))>0:
            win32api.MessageBox(0, "success,请到路径C:\\Users\\xyy\\Desktop\\150.xlsx查看表格", "提醒", win32con.MB_OK) else:
            win32api.MessageBox(0, "error", "提醒", win32con.MB_OK) # self.centralWidget.close()  #  # ###===========读取表格,转换表格,===========================================  # if len(path_openfile_name) > 0:  #     input_table = b  # #print(input_table)  #     input_table_rows = input_table.shape[0]  #     input_table_colunms = input_table.shape[1]  # #print(input_table_rows)  # #print(input_table_colunms)  #     input_table_header = input_table.columns.values.tolist()  # #print(input_table_header)  #  # ###===========读取表格,转换表格,============================================  # ###======================给tablewidget设置行列表头============================  #  #     self.tableWidget.setColumnCount(input_table_colunms)  #     self.tableWidget.setRowCount(input_table_rows)  #     self.tableWidget.setHorizontalHeaderLabels(input_table_header)  #  # ###======================给tablewidget设置行列表头============================  #  # ###================遍历表格每个元素,同时添加到tablewidget中========================  #     for i in range(input_table_rows):  #         input_table_rows_values = input_table.iloc[[i]]  #         #print(input_table_rows_values)  #         input_table_rows_values_array = np.array(input_table_rows_values)  #         input_table_rows_values_list = input_table_rows_values_array.tolist()[0]  #     #print(input_table_rows_values_list)  #         for j in range(input_table_colunms):  #             input_table_items_list = input_table_rows_values_list[j]  #         #print(input_table_items_list)  #         # print(type(input_table_items_list))  #  # ###==============将遍历的元素添加到tablewidget中并显示=======================  #  #             input_table_items = str(input_table_items_list)  #             newItem = QTableWidgetItem(input_table_items)  #             newItem.setTextAlignment(Qt.AlignHCenter|Qt.AlignVCenter)  #             self.tableWidget.setItem(i, j, newItem)  #  # ###================遍历表格每个元素,同时添加到tablewidget中========================  # else:  #     self.centralWidget.show()   if __name__ == "__main__": import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

实例下载地址

python数据分析与处理

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警