欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python實(shí)現(xiàn)xlsx文件分析詳解

 更新時(shí)間:2018年01月02日 11:06:32   作者:水似冰  
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)xlsx文件分析,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

python腳本實(shí)現(xiàn)xlsx文件解析,供大家參考,具體內(nèi)容如下

環(huán)境配置:

1.系統(tǒng)環(huán)境:Windows 7 64bit
2.編譯環(huán)境:Python3.4.3
3.依賴庫(kù): os sys xlrd re
4.其他工具:none
5.前置條件:待處理的xlsx文件

腳本由來(lái)

最近的工作是做測(cè)試,而有一項(xiàng)任務(wù)呢,就是分析每天機(jī)器人巡檢時(shí)采集的數(shù)據(jù),包括各種傳感器,CO2、O2、噪聲等等,每天的數(shù)據(jù)也有上千條,通過(guò)站控的導(dǎo)出數(shù)據(jù)功能,會(huì)把數(shù)據(jù)庫(kù)里面導(dǎo)出成xlsx文件,而這項(xiàng)任務(wù)要分析一下當(dāng)天采集的數(shù)據(jù)是否在正常范圍,要計(jì)算攝像頭的識(shí)別率和識(shí)別準(zhǔn)確率,自己傻呵呵的每天都在手動(dòng)操作,突然覺(jué)得很浪費(fèi)時(shí)間,索性寫(xiě)個(gè)python腳本吧,這樣每天一條命令,就能得到自己想看的數(shù)據(jù)結(jié)果。每天至少節(jié)省10分鐘!
這是要解析的xlsx文件: 

 

一般手動(dòng)就得篩選、排序、打開(kāi)計(jì)算器計(jì)算 - - 繁瑣枯燥乏味
還是python大法好

代碼淺析

流程圖

腳本demo

#-*- coding:utf-8 -*-
import xlrd
import os
import sys
import logging
import re
#logging.basicConfig(level=logging.DEBUG)

xfile = sys.argv[1]

dateList = []
InspectionType = []
InspectionRresult = []

def load_data():

  CO2Type = []
  O2Type = []
  NoiseType = []
  SupwareType = []
  TowareType = []
  TemperatureType = []
  HumidityType = []
  InfraredType = []

  CO2Result = []
  O2Result = []
  NoiseResult = []
  SupwareResult = []
  TowareResult = []
  TemperatureResult = []
  HumidityResult = []
  InfraredResult = []

  logging.debug(InspectionType)
  logging.debug(InspectionRresult)


  for index, value in enumerate(InspectionType):
    if value == "二氧化碳":                   #CO2Type
      CO2Type.extend(value)
      logging.debug(index)
      logging.debug("CO2 RESULT:  "+InspectionRresult[index])
      CO2Result.append(InspectionRresult[index])

    if value == "氧氣傳感器":                  #O2Type
      O2Type.extend(value)
      O2Result.append(InspectionRresult[index])

    if value == "噪聲傳感器":                  #NoiseType
      NoiseType.extend(value)
      NoiseResult.append(InspectionRresult[index])


    if value == "局放(超聲波測(cè)量)":               #SupwareType
      SupwareType.extend(value)
      SupwareResult.append(InspectionRresult[index])

    if value == "局放(地電波測(cè)量)":               #SupwareType
      TowareType.extend(value)
      TowareResult.append(InspectionRresult[index])

    if value == "溫度傳感器":                  #TemperatureType
      TemperatureType.extend(value)
      TemperatureResult.append(InspectionRresult[index])      

    if value == "濕度傳感器":                  #TemperatureType
      HumidityType.extend(value)
      HumidityResult.append(InspectionRresult[index])

    if value == "溫度(紅外測(cè)量)":                  #TemperatureType
      InfraredType.extend(value)
      InfraredResult.append(InspectionRresult[index])      
  logging.debug(CO2Result)
  logging.debug(O2Result)
  logging.debug(NoiseResult)
  logging.debug(SupwareResult)
  logging.debug(TowareResult)
  logging.debug(TemperatureResult)
  logging.debug(HumidityResult)    
  logging.debug(InfraredResult)   
  return CO2Result,O2Result,NoiseResult,SupwareResult,TowareResult,TemperatureResult,HumidityResult,InfraredResult

def get_data_print(co2,o2,noise,supware,toware,temperature,humidity,infrared):
  co2 = list(map(eval,co2))
  o2 = list(map(eval,o2))
  noise = list(map(eval,noise))
  supware = list(map(eval,supware))
  toware = list(map(eval,toware))
  temperature = list(map(eval,temperature))
  humidity = list(map(eval,humidity))
  infrared = list(map(eval,infrared))

  co2Min = min(co2)
  co2Max = max(co2)
  logging.debug("CO2 min value :~~"+str(co2Min))
  logging.debug("CO2 max value :~~"+str(co2Max))

  o2Min = min(o2)
  o2Max = max(o2)
  noiseMin = min(noise)
  noiseMax = max(noise)

  supwareMin = min(supware)
  supwareMax = max(supware)

  towareMin = min(toware)
  towareMax = max(toware)

  temperatureMin = min(temperature)
  temperatureMax = max(temperature)

  humidityMin = min(humidity)
  humidityMax = max(humidity)

  infraredMin = min(infrared)
  infraredMax = max(infrared)

  print("CO2 values :",co2Min,'~~~~~~~',co2Max)
  print("o2 values :",o2Min,'~~~~~~~',o2Max)
  print("noise values :",noiseMin,'~~~~~~~',noiseMax)
  print("supware values :",supwareMin,'~~~~~~~',supwareMax)
  print("toware values :",towareMin,'~~~~~~~',towareMax)
  print("temperature values :",temperatureMin,'~~~~~~~',temperatureMax)
  print("humidity values :",humidityMin,'~~~~~~~',humidityMax)
  print("infrared values :",infraredMin,'~~~~~~~',infraredMax)

def cal_picture():
  result7to19List = []
  result19to7List = []
  count7to19List = []
  count19to7List = []
  count7to19Dict = {}
  count19to7Dict = {}

  failfind7to19cnt = 0
  failfind19to7cnt = 0
  photoType = []
  photoDateList = []
  allPhotoResult = []

  for index,value in enumerate(InspectionType):            #按照巡檢類型篩選出視覺(jué)類,通過(guò)索引值同步時(shí)間、巡檢結(jié)果
    if value == "開(kāi)關(guān)(視覺(jué)識(shí)別)" or value == "旋鈕(視覺(jué)識(shí)別)" or \
      value == "電流表(視覺(jué)識(shí)別)" or value == "電壓表(視覺(jué)識(shí)別)":
      photoType.extend(value)
      photoDateList.append(dateList[index])
      allPhotoResult.append(InspectionRresult[index])
  for index,value in enumerate(photoDateList):
    if value[-8:] > '07:00:00' and value[-8:] < '19:00:00':
      result7to19List.append(allPhotoResult[index])
    if value[-8:] > '19:00:00' or value[-8:] < '7:00:00':
      result19to7List.append(allPhotoResult[index])

  logging.debug(result7to19List[-20:])
  logging.debug(result19to7List[:20])

  noduplicate7to19Set=set(result7to19List)              #里面無(wú)重復(fù)項(xiàng)
  for item in noduplicate7to19Set:
    count7to19List.append(result7to19List.count(item))
  logging.debug(count7to19List)
  count7to19Dict= dict(zip(list(noduplicate7to19Set),count7to19List))

  noduplicate19to7Set=set(result19to7List)              
  for item in noduplicate19to7Set:
    count19to7List.append(result19to7List.count(item))
  count19to7Dict= dict(zip(list(noduplicate19to7Set),count19to7List))

  logging.debug(count7to19Dict)

  None7to19cnt = count7to19Dict['']
  all7to19cnt = len(result7to19List)
  None19to7cnt = count19to7Dict['']
  all19to7cnt = len(result19to7List)

  logging.debug(None7to19cnt)

  for key in count7to19Dict:
    if count7to19Dict[key] == 1 :
      failfind7to19cnt = failfind7to19cnt+1
    if re.match('識(shí)別失敗:*',key):
      failfind7to19cnt = failfind7to19cnt+ count7to19Dict[key]

  for key in count19to7Dict:
    if count19to7Dict[key] == 1 :
      failfind19to7cnt = failfind19to7cnt+1 
    if re.match('識(shí)別失敗:*',key):
      failfind19to7cnt = failfind19to7cnt+count19to7Dict[key]
  logging.debug(all19to7cnt)

  print("7:00 ~~~ 19:00 識(shí)別率:",(all7to19cnt-None7to19cnt)/all7to19cnt)
  print("7:00 ~~~ 19:00 識(shí)別準(zhǔn)確率:",(all7to19cnt-None7to19cnt-failfind7to19cnt)/(all7to19cnt-None7to19cnt))
  print("19:00 ~~~ 7:00 識(shí)別率:",(all19to7cnt-None19to7cnt)/all19to7cnt)
  print("19:00 ~~~ 7:00 識(shí)別準(zhǔn)確率:",(all19to7cnt-None19to7cnt-failfind19to7cnt)/(all19to7cnt-None19to7cnt))
#讀取xlsx文件
xlsxdata=xlrd.open_workbook(xfile)
tablepage=xlsxdata.sheets()[0]
dateList.extend(tablepage.col_values(5))
InspectionType.extend(tablepage.col_values(3))
InspectionRresult.extend(tablepage.col_values(6))

cal_picture()
co2,o2,noise,supware,toware,temperature,humidity,infrared=load_data()
get_data_print(co2,o2,noise,supware,toware,temperature,humidity,infrared)

結(jié)果圖

回顧與總結(jié)

漸漸體會(huì)到python腳本的優(yōu)勢(shì)所在。
python在代碼保密上可能是解釋性語(yǔ)言共有的小小缺陷,做項(xiàng)目還是C/C++,當(dāng)然是指?jìng)鹘y(tǒng)項(xiàng)目
寫(xiě)python很開(kāi)心啊

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Python中Pygame鍵盤(pán)事件

    詳解Python中Pygame鍵盤(pán)事件

    今天給大家?guī)?lái)的是關(guān)于Python的相關(guān)知識(shí),文章圍繞著Pygame鍵盤(pán)事件展開(kāi),文中有非常詳細(xì)的介紹及代碼示例,需要的朋友可以參考下
    2021-06-06
  • PyQt5的PyQtGraph實(shí)踐系列3之實(shí)時(shí)數(shù)據(jù)更新繪制圖形

    PyQt5的PyQtGraph實(shí)踐系列3之實(shí)時(shí)數(shù)據(jù)更新繪制圖形

    這篇文章主要介紹了PyQt5的PyQtGraph實(shí)踐系列3之實(shí)時(shí)數(shù)據(jù)更新繪制圖形,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-05-05
  • python加密打包程序詳解

    python加密打包程序詳解

    這篇文章主要介紹了python加密打包程序,還給大家介紹了Python實(shí)現(xiàn)文件簡(jiǎn)單加解密的方法,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-04-04
  • Python中itertools模塊用法詳解

    Python中itertools模塊用法詳解

    這篇文章主要介紹了Python中itertools模塊用法,詳細(xì)的講述了itertools模塊中常見(jiàn)函數(shù)的用法及相關(guān)示例,有助于深入掌握Python程序設(shè)計(jì),需要的朋友可以參考下
    2014-09-09
  • python tkinter模塊的簡(jiǎn)單使用

    python tkinter模塊的簡(jiǎn)單使用

    這篇文章主要介紹了python tkinter模塊的簡(jiǎn)單使用,幫助大家更好的理解和學(xué)習(xí)使用python制作gui界面,感興趣的朋友可以了解下
    2021-04-04
  • Django中prefetch_related()函數(shù)優(yōu)化實(shí)戰(zhàn)指南

    Django中prefetch_related()函數(shù)優(yōu)化實(shí)戰(zhàn)指南

    我們可以利用Django框架中select_related和prefetch_related函數(shù)對(duì)數(shù)據(jù)庫(kù)查詢優(yōu)化,這篇文章主要給大家介紹了關(guān)于Django中prefetch_related()函數(shù)優(yōu)化的相關(guān)資料,需要的朋友可以參考下
    2022-11-11
  • Django 解決開(kāi)發(fā)自定義拋出異常的問(wèn)題

    Django 解決開(kāi)發(fā)自定義拋出異常的問(wèn)題

    這篇文章主要介紹了Django 解決開(kāi)發(fā)自定義拋出異常的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-05-05
  • python人工智能tensorflow函數(shù)np.random模塊使用

    python人工智能tensorflow函數(shù)np.random模塊使用

    這篇文章主要為大家介紹了python人工智能tensorflow函數(shù)np.random模塊使用方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • Django自定義過(guò)濾器定義與用法示例

    Django自定義過(guò)濾器定義與用法示例

    這篇文章主要介紹了Django自定義過(guò)濾器定義與用法,結(jié)合實(shí)例形式分析了Django自定義過(guò)濾器的概念、功能、定義及使用方法,需要的朋友可以參考下
    2018-03-03
  • python scipy 稀疏矩陣的使用說(shuō)明

    python scipy 稀疏矩陣的使用說(shuō)明

    這篇文章主要介紹了python scipy 稀疏矩陣的使用說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-05-05

最新評(píng)論