pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <i id='6tJ2c'><tr id='6tJ2c'><dt id='6tJ2c'><q id='6tJ2c'><span id='6tJ2c'><b id='6tJ2c'><form id='6tJ2c'><ins id='6tJ2c'></ins><ul id='6tJ2c'></ul><sub id='6tJ2c'></sub></form><legend id='6tJ2c'></legend><bdo id='6tJ2c'><pre id='6tJ2c'><center id='6tJ2c'></center></pre></bdo></b><th id='6tJ2c'></th></span></q></dt></tr></i><div class="oj2fw8g" id='6tJ2c'><tfoot id='6tJ2c'></tfoot><dl id='6tJ2c'><fieldset id='6tJ2c'></fieldset></dl></div>
      <legend id='6tJ2c'><style id='6tJ2c'><dir id='6tJ2c'><q id='6tJ2c'></q></dir></style></legend>

      <small id='6tJ2c'></small><noframes id='6tJ2c'>

      • <bdo id='6tJ2c'></bdo><ul id='6tJ2c'></ul>
      <tfoot id='6tJ2c'></tfoot>

    1. 如何在python中將文件保存為excel時(shí)顯示進(jìn)度條?

      How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時(shí)顯示進(jìn)度條?)
      <tfoot id='2yogC'></tfoot>

      <i id='2yogC'><tr id='2yogC'><dt id='2yogC'><q id='2yogC'><span id='2yogC'><b id='2yogC'><form id='2yogC'><ins id='2yogC'></ins><ul id='2yogC'></ul><sub id='2yogC'></sub></form><legend id='2yogC'></legend><bdo id='2yogC'><pre id='2yogC'><center id='2yogC'></center></pre></bdo></b><th id='2yogC'></th></span></q></dt></tr></i><div class="zutyb7f" id='2yogC'><tfoot id='2yogC'></tfoot><dl id='2yogC'><fieldset id='2yogC'></fieldset></dl></div>
        <tbody id='2yogC'></tbody>

      <small id='2yogC'></small><noframes id='2yogC'>

                <bdo id='2yogC'></bdo><ul id='2yogC'></ul>

                <legend id='2yogC'><style id='2yogC'><dir id='2yogC'><q id='2yogC'></q></dir></style></legend>
              • 本文介紹了如何在python中將文件保存為excel時(shí)顯示進(jìn)度條?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                如果你能幫助我,不勝感激.將文件保存到 Excel 時(shí),我無法顯示進(jìn)度條.我想要實(shí)現(xiàn)的是顯示進(jìn)度條,同時(shí)從 pandas dataframe 也從 qwidgettable 保存 excel 文件,因?yàn)樗枰獣r(shí)間才能保存.在下載或保存 excel 文件之前,我希望該進(jìn)度條關(guān)閉.我試著在網(wǎng)上查看,但我看不到我的查詢的具體答案.到目前為止,這是我創(chuàng)建的編譯代碼.

                Appreciate if you could help me. I have a trouble showing up the progress bar while saving file to excel. What I want to achieve is to show a progress bar while saving excel file from a pandas dataframe also from qwidgettable as it takes time before it saves. Until the excel file is downloaded or saved i want that progress bar to close. I tried looking over the net but I cant see specific answers to my query. So far, this is the compiled codes I have created.

                import sys
                from PyQt5 import QtWidgets, QtCore
                import pandas as pd
                import time
                import psutil
                
                
                class ThreadClass(QtCore.QThread):
                   updateProgressBar = QtCore.pyqtSignal(int)
                
                   def __init__(self, parent=None):
                       super(ThreadClass, self).__init__(parent)
                
                   def run(self):
                       while True:
                           val = int(psutil.cpu_percent())
                           time.sleep(1)
                           self.updateProgressBar.emit(val)
                
                class Window(QtWidgets.QMainWindow):
                    def __init__(self):
                        super(Window, self).__init__()
                        self.setGeometry(50,50,500,500)
                        self.setWindowTitle('PyQt Tuts')
                        self.table()
                
                    def updateProgressBar(self, val):
                        self.progressBar.setValue(val)
                
                    def table(self):
                        self.tableWidget = QtWidgets.QTableWidget()
                        self.tableWidget.setGeometry(QtCore.QRect(220, 100, 411, 392))
                        self.tableWidget.setColumnCount(2)
                        self.tableWidget.setRowCount(5)
                        self.tableWidget.show()
                
                        item = QtWidgets.QTableWidgetItem()
                        item.setText("Amount")
                        self.tableWidget.setHorizontalHeaderItem(1, item)
                
                        records = [
                            ['Product 1', 1000],
                            ['Product 2', 500],
                            ['Product 3', 600],
                            ['Product 4', 300],
                            ['Product 5', 800],
                        ]
                
                        self.df = pd.DataFrame(records, columns=['Name', 'Amount'])
                
                        for r in range(5):
                            for c in range(2):
                                table_item = str(self.df.iloc[r, c])
                                self.tableWidget.setItem(r, c, QtWidgets.QTableWidgetItem(table_item))
                
                        self.pb_extract = QtWidgets.QPushButton(self.tableWidget)
                        self.pb_extract.setGeometry(QtCore.QRect(10, 200, 75, 23))
                        self.pb_extract.clicked.connect(self.extract)
                        self.pb_extract.setText("EXTRACT")
                        self.pb_extract.show()
                
                    def extract(self):
                        self.lb_downloading = QtWidgets.QLabel(self.tableWidget)
                        self.lb_downloading.setGeometry(QtCore.QRect(10, 270, 81, 16))
                        self.lb_downloading.setText("Downloading..")
                        self.lb_downloading.show()
                
                        self.progressBar = QtWidgets.QProgressBar(self.tableWidget)
                        self.progressBar.setGeometry(QtCore.QRect(10, 290, 171, 10))
                        self.progressBar.show()
                
                        self.threadclass = ThreadClass()
                        self.threadclass.start()
                        self.threadclass.updateProgressBar.connect(self.updateProgressBar)
                
                        self.df.to_excel('Products.xlsx', index=False)
                        print('Download complete!')
                
                def run():
                    app = QtWidgets.QApplication(sys.argv)
                    app.setStyle("fusion")
                    w = Window()
                    sys.exit(app.exec_())
                
                run()
                

                這些代碼如下所示:

                我想要實(shí)現(xiàn)的是當(dāng)我單擊提取按鈕時(shí),下載進(jìn)度條將關(guān)閉,直到 excel 文件完全下載/保存.

                what i want to achieve is when i click the extract button, the downloading progressbar will close until the excel file fully downloaded/saved.

                (PS 我只是得到 val = int(psutil.cpu_percent()) 的隨機(jī)值,因?yàn)槲乙膊恢涝趹?yīng)用程序運(yùn)行時(shí)使用什么特定代碼/函數(shù)只是為了顯示告訴你我有一個(gè)進(jìn)度條在移動.)

                (P.S i just get random values for val = int(psutil.cpu_percent()) because i also don't know what specific code/function to use while the app is running just to show to you that i have a progress bar moving.)

                提前謝謝你!

                推薦答案

                這類問題在SO里被問過無數(shù)次了,而且很多時(shí)候在評論里解釋過需求說明什么情況下才有可能,在哪些情況下是不可能的.所以為了避免重復(fù)同樣的事情,我將根據(jù)OP的問題在這篇文章中解釋這個(gè)主題.

                一個(gè)小部件通常用于顯示和/或從用戶那里獲取信息,QProgressBar 做第一件事,也就是說,它顯示進(jìn)度信息,它不計(jì)算一下.

                A widget in general is used to show and/or obtain information from the user, and a QProgressBar does the first thing, that is, it shows the progress information, it does not calculate it.

                如果可以將任務(wù)細(xì)分為n"個(gè)子任務(wù),則可以計(jì)算進(jìn)度,因?yàn)樗喈?dāng)于已經(jīng)完成的子任務(wù)數(shù)相對于總子任務(wù)數(shù).

                Progress can be calculated if the task can be subdivided into "n" subtasks, since it would be equivalent to the number of subtasks already done with respect to the number of total subtasks.

                • 比如任務(wù)是上傳一個(gè)N KB的文件到服務(wù)器,那么每個(gè)子任務(wù)可以有1KB的信息,所以進(jìn)度是:

                • For example if the task is to upload a N KB file to a server, then each subtask can be 1KB of information, so the progress would be:

                progress = 100 * number_of_KB_submitted/number_of_KB_of_file
                

              • 另一個(gè)例子是如果你必須復(fù)制 n 個(gè)文件,那么進(jìn)度是:

              • Another example would be if you have to copy n files, then the progress would be:

                progress = 100 * number_of_copied_files / number_of_total_files
                

              • 從上面可以看出,只有任務(wù)可以細(xì)分為子任務(wù),才能計(jì)算進(jìn)度,所以如果任務(wù)不能細(xì)分,就不可能計(jì)算任何進(jìn)度.

                From the above it is obvious that progress can only be calculated if the task can be subdivided into subtasks, so if the task cannot be subdivided then it is impossible to calculate any progress.

                在將 pandas 保存在 excel 中的情況下,很明顯它不能細(xì)分為n"個(gè)任務(wù),因此無法計(jì)算其進(jìn)度.

                In the case of saving the pandas in an excel it is obvious that it cannot be subdivided into "n" tasks so it will be impossible to calculate its progress.

                在使用 to_excel 將 pandas 保存在 excel 中的情況下,很明顯它不能細(xì)分為n"個(gè)任務(wù),因此無法計(jì)算其進(jìn)度.

                In the case of saving the pandas in an excel using to_excel it is obvious that it cannot be subdivided into "n" tasks so it will be impossible to calculate its progress.

                在這些情況下的解決方法是顯示繁忙的 QProgressBar:

                A workaround in those cases is to show a busy QProgressBar:

                progressbar.setRange(0, 0)
                

                在你的情況下:

                import sys
                from PyQt5 import QtWidgets, QtCore
                import pandas as pd
                import time
                
                import threading
                
                
                class ExcelWorker(QtCore.QObject):
                    started = QtCore.pyqtSignal()
                    finished = QtCore.pyqtSignal()
                
                    def execute(self, df, filename):
                        threading.Thread(target=self._execute, args=(df, filename), daemon=True).start()
                
                    def _execute(self, df, filename):
                        self.started.emit()
                        df.to_excel(filename, index=False)
                        self.finished.emit()
                
                
                class DownloaderProgressBar(QtWidgets.QWidget):
                    def __init__(self, parent=None):
                        super(DownloaderProgressBar, self).__init__(parent)
                
                        self._progressbar = QtWidgets.QProgressBar()
                
                        lay = QtWidgets.QVBoxLayout(self)
                        lay.addWidget(QtWidgets.QLabel(self.tr("Downloading..")))
                        lay.addWidget(self.progressbar)
                
                    @property
                    def progressbar(self):
                        return self._progressbar
                
                
                class Window(QtWidgets.QMainWindow):
                    def __init__(self):
                        super(Window, self).__init__()
                        self.setGeometry(50, 50, 500, 500)
                        self.setWindowTitle("PyQt Tuts")
                        self.create_table()
                
                        self.create_progressbar()
                        self.create_worker()
                
                    def create_progressbar(self):
                        self.downloader_progressbar = DownloaderProgressBar(self.tableWidget)
                        self.downloader_progressbar.setGeometry(10, 270, 170, 80)
                        self.downloader_progressbar.hide()
                
                    def create_worker(self):
                        self.worker = ExcelWorker()
                        self.worker.started.connect(self.on_started)
                        self.worker.finished.connect(self.on_finished)
                
                    def create_table(self):
                        self.tableWidget = QtWidgets.QTableWidget()
                        self.tableWidget.setGeometry(QtCore.QRect(220, 100, 411, 392))
                        self.tableWidget.setColumnCount(2)
                        self.tableWidget.setRowCount(5)
                        self.tableWidget.show()
                
                        item = QtWidgets.QTableWidgetItem()
                        item.setText("Amount")
                        self.tableWidget.setHorizontalHeaderItem(1, item)
                
                        records = [
                            ["Product 1", 1000],
                            ["Product 2", 500],
                            ["Product 3", 600],
                            ["Product 4", 300],
                            ["Product 5", 800],
                        ]
                
                        self.df = pd.DataFrame(records, columns=["Name", "Amount"])
                
                        for r in range(5):
                            for c in range(2):
                                table_item = str(self.df.iloc[r, c])
                                self.tableWidget.setItem(r, c, QtWidgets.QTableWidgetItem(table_item))
                
                        self.pb_extract = QtWidgets.QPushButton(self.tableWidget)
                        self.pb_extract.setGeometry(QtCore.QRect(10, 200, 75, 23))
                        self.pb_extract.clicked.connect(self.extract)
                        self.pb_extract.setText("EXTRACT")
                        self.pb_extract.show()
                
                    def extract(self):
                        self.worker.execute(self.df.copy(), "Products.xlsx")
                        self.downloader_progressbar.show()
                
                    @QtCore.pyqtSlot()
                    def on_started(self):
                        self.downloader_progressbar.progressbar.setRange(0, 0)
                
                    @QtCore.pyqtSlot()
                    def on_finished(self):
                        self.downloader_progressbar.progressbar.setRange(0, 1)
                
                
                def run():
                    app = QtWidgets.QApplication(sys.argv)
                    app.setStyle("fusion")
                    w = Window()
                    sys.exit(app.exec_())
                
                
                run()
                

                這篇關(guān)于如何在python中將文件保存為excel時(shí)顯示進(jìn)度條?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                PyQt progress jumps to 100% after it starts(PyQt 啟動后進(jìn)度躍升至 100%)
                How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動時(shí),yaxis 刻度標(biāo)簽應(yīng)該可見
                `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                Erasing pen on a canvas(在畫布上擦筆)

                  <tbody id='2Qmee'></tbody>

                <small id='2Qmee'></small><noframes id='2Qmee'>

                • <bdo id='2Qmee'></bdo><ul id='2Qmee'></ul>

                  1. <tfoot id='2Qmee'></tfoot>

                      1. <i id='2Qmee'><tr id='2Qmee'><dt id='2Qmee'><q id='2Qmee'><span id='2Qmee'><b id='2Qmee'><form id='2Qmee'><ins id='2Qmee'></ins><ul id='2Qmee'></ul><sub id='2Qmee'></sub></form><legend id='2Qmee'></legend><bdo id='2Qmee'><pre id='2Qmee'><center id='2Qmee'></center></pre></bdo></b><th id='2Qmee'></th></span></q></dt></tr></i><div class="cskcytl" id='2Qmee'><tfoot id='2Qmee'></tfoot><dl id='2Qmee'><fieldset id='2Qmee'></fieldset></dl></div>
                          <legend id='2Qmee'><style id='2Qmee'><dir id='2Qmee'><q id='2Qmee'></q></dir></style></legend>

                          主站蜘蛛池模板: 小型玉石雕刻机_家用玉雕机_小型万能雕刻机_凡刻雕刻机官网 | 承插管件_不锈钢承插管件_锻钢高压管件-温州科正阀门管件有限公司 | 冷却塔厂家_冷却塔维修_冷却塔改造_凉水塔配件填料公司- 广东康明节能空调有限公司 | 建筑资质代办-建筑企业资质代办机构-建筑资质代办公司 | 商标转让-商标注册-商标查询-软著专利服务平台 - 赣江万网 | 合金耐磨锤头_破碎机锤头_郑州市德勤建材有限公司 | 换网器_自动换网器_液压换网器--郑州海科熔体泵有限公司 | 减速机三参数组合探头|TSM803|壁挂式氧化锆分析仪探头-安徽鹏宸电气有限公司 | 广东风淋室_广东风淋室厂家_广东风淋室价格_广州开源_传递窗_FFU-广州开源净化科技有限公司 | T恤衫定做,企业文化衫制作订做,广告T恤POLO衫定制厂家[源头工厂]-【汉诚T恤定制网】 | 无锡网站建设-做网站-建网站-网页设计制作-阿凡达建站公司 | 自动螺旋上料机厂家价格-斗式提升机定制-螺杆绞龙输送机-杰凯上料机 | 飞扬动力官网-广告公司管理软件,广告公司管理系统,喷绘写真条幅制作管理软件,广告公司ERP系统 | 卷筒电缆-拖链电缆-特种柔性扁平电缆定制厂家「上海缆胜」 | 并网柜,汇流箱,电控设备,中高低压开关柜,电气电力成套设备,PLC控制设备订制厂家,江苏昌伟业新能源科技有限公司 | 北京浩云律师事务所-法律顾问_企业法务_律师顾问_公司顾问 | 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | 硬齿面减速机_厂家-山东安吉富传动设备股份有限公司 | 电机保护器-电动机综合保护器-浙江开民| 蒜肠网-动漫,二次元,COSPLAY,漫展以及收藏型模型,手办,玩具的新媒体.(原变形金刚变迷TF圈) | 电磁流量计_智能防腐防爆管道式计量表-金湖凯铭仪表有限公司 | 北京网站建设公司_北京网站制作公司_北京网站设计公司-北京爱品特网站建站公司 | 高压负荷开关-苏州雷尔沃电器有限公司 | 免费个人pos机申请办理-移动pos机刷卡-聚合收款码办理 | 驾驶人在线_专业学车门户网站 | 耐酸泵,耐腐蚀真空泵,耐酸真空泵-淄博华舜耐腐蚀真空泵有限公司 精密模具-双色注塑模具加工-深圳铭洋宇通 | 祝融环境-地源热泵多恒系统高新技术企业,舒适生活环境缔造者! | 动物麻醉机-数显脑立体定位仪-北京易则佳科技有限公司 | 电车线(用于供电给电车的输电线路)-百科 | 海水晶,海水素,海水晶价格-潍坊滨海经济开发区强隆海水晶厂 | 大流量卧式砂磨机_强力分散机_双行星双动力混合机_同心双轴搅拌机-莱州市龙跃化工机械有限公司 | 宁波普瑞思邻苯二甲酸盐检测仪,ROHS2.0检测设备,ROHS2.0测试仪厂家 | 假肢-假肢价格-假肢厂家-河南假肢-郑州市力康假肢矫形器有限公司 | 361°官方网站| 二手色谱仪器,十万分之一分析天平,蒸发光检测器,电位滴定仪-湖北捷岛科学仪器有限公司 | 沈阳液压泵_沈阳液压阀_沈阳液压站-沈阳海德太科液压设备有限公司 | 运动木地板厂家,篮球场木地板品牌,体育场馆木地板安装 - 欧氏运动地板 | 护腰带生产厂家_磁石_医用_热压护腰_登山护膝_背姿矫正带_保健护具_医疗护具-衡水港盛 | 洁净实验室工程-成都手术室净化-无尘车间装修-四川华锐净化公司-洁净室专业厂家 | 大连海岛旅游网>>大连旅游,大连海岛游,旅游景点攻略,海岛旅游官网 | 南京泽朗生物科技有限公司 |