#-*- coding: utf-8 -*-
import
pandas as pda
import
matplotlib.pyplot as pyl
import
matplotlib.font_manager
from collections import
counter
'''配置變數區--start--
'''zhibanfile = '
zhibanbiao.xlsx
'week = 6 #
排班排了幾周
colstart = 2 #
從0開始,要統計資料開始列
colend = 9 #
從0開始,要統計資料結束列
rowend = week*4+1dimdict =
print('
讀取的檔案為:
' +zhibanfile)
print('
排班排了幾周:
' +str(week))
print('
參與值班的人員:')
(dimdict)
'''配置變數區--end--
''''''
讀取檔案進行處理--start--
'''data =pda.read_excel(zhibanfile)
content =data.values
listday =
listnight =
for row in range(2,rowend,4):
for col in range(2,colend):
cellorginal =str(content[row][col])
cell = cellorginal.strip().replace('
\n','
,').split('
,')[0:2]
for row in range(3,25,4):
for col in range(2,colend):
cellorginal =str(content[row][col])
cell = cellorginal.strip().replace('
\n','
,').split('
,')[0:2]
#下面為白班處理
daydic = counter(listday) #
對list中資料根據個數進行統計,形成key,value的格式
xday = list(daydic.keys()) #
值班人員編號
yday = list(daydic.values()) #
值班人員班次個數
xdaylabel =
for x in
xday:
daydic =counter(listday)
xday =list(daydic.keys())
yday =list(daydic.values())
#下面為夜班處理
nightdic =counter(listnight)
xnight =list(nightdic.keys())
ynight =list(nightdic.values())
xnightlabel =
for x in
xnight:
'''讀取檔案進行處理--end--
''''''
畫圖--start--
'''f = pyl.figure('
監控室值班統計')
zhfont = matplotlib.font_manager.fontproperties(fname='
c:\windows\fonts\simkai.ttf
') #
設定字型格式
pyl.subplot(2,1,1) #
白班pyl.xticks(range(len(xdaylabel)),xdaylabel,fontproperties=zhfont)
pyl.plot(yday,'b
')pyl.ylim(0,12)
pyl.grid(true)
pyl.title('白班
',fontproperties=zhfont)
pyl.subplot(2,1,2) #
夜班pyl.xticks(range(len(xnightlabel)),xnightlabel,fontproperties=zhfont)
pyl.plot(ynight,'g
')pyl.ylim(0,12)
pyl.grid(true)
pyl.title('夜班
',fontproperties=zhfont)
pyl.show()
'''畫圖--end--
'''
python 讀取Excel資料
如果xlrd執行報錯,先解除安裝當前安裝的xlrd pip uninstall xlrd 再安裝低版本的xlrd pip install xlrd 1.2.0 import xlrd import sysimport osdef read excel dict excelpath,sheetname...
讀取Excel資料
方法2 相當簡單,excel就像資料庫,每個sheet就是乙個table.microsoft.jet.oledb驅動.之後是datareader迴圈,或dataset處理都非常簡單.注意 資料型別的轉換 region set connection string strconn provider mi...
讀取Excel資料
excel2007的連線字串與excel2003的不同。datatable tbsheetname connection.getoledbschematable oledbschemaguid.tables,null 用來獲得sheet的名字 using system using system.io...