日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python对excel表统计视频教程_Python实现对excel文件列表值进行统计的方法

發(fā)布時間:2023/12/20 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python对excel表统计视频教程_Python实现对excel文件列表值进行统计的方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文實例講述了Python實現(xiàn)對excel文件列表值進行統(tǒng)計的方法。分享給大家供大家參考。具體如下:

#!/usr/bin/env python

#coding=gbk

#此PY用來統(tǒng)計一個execl文件中的特定一列的值的分類

import win32com.client

filename=raw_input("請輸入要統(tǒng)計文件的詳細地址:")

flag=0 #用于判斷文件 名如果不帶‘日'就為 0

if '\xc8\xd5' in filename:flag=1

print 50*'='+'\n\t 請稍等,程序正在統(tǒng)計中。。。'

try:

xls=win32com.client.Dispatch('et.Application')

try:

xlsfile=xls.Workbooks.Open(filename)

#打開指定的文件,一般打開的是sheet1

sheet=xlsfile.Worksheets('Sheet1')

except:

print '文件找開錯誤!'

exit(1)

print '程序正在自動退出。。。'

if sheet.Cells(3,6).Value!=u'業(yè)務(wù)類型' or sheet.Cells(3,3).Value!=u'轉(zhuǎn)辦單位':

print '您輸入的表格已不是默認的表格,數(shù)據(jù)格式有誤'

exit(1) #這個判斷是當文件中的特定列改變時,直接退出程序

i=4

dept=sheet.Cells(i,3).Value

type=sheet.Cells(i,6).Value

typelist=[] #用于存放數(shù)據(jù)的列表,下面就是取sheet表里的某一列數(shù)據(jù)

deptlist=[] #用于存放轉(zhuǎn)辦單位的列表

while type:

typelist.append(type)

deptlist.append(dept)

i=i+1

type=sheet.Cells(i,6).Value

dept=sheet.Cells(i,3).Value

#存放列的數(shù)據(jù)到二個列表中

counts=len(typelist) #總件數(shù)

if counts==0:

print '輸入的文件統(tǒng)計結(jié)果為0,是否文件的格式有誤?'

exit(1)

typelist=[(i,typelist.count(i)) for i in set(typelist)]

departmentlist=[]

delchar='0123456789' #刪除取出列表中有可能帶數(shù)字 分開字段有空格的話

for i in deptlist[:]:

i=''.join([j for j in i if j not in delchar])

while '.' in i: i=i.replace('.',' ')

deptlist+=i.split()

deptlist=deptlist[counts:]

deptlist=[(i,deptlist.count(i)) for i in set(deptlist)]

#下面是打印格式等 。。。

print '\n'+50*'='

print '\t信訪件總數(shù)為%d件,下面是各分類件數(shù)' % counts,

print '\n'+50*'='+'\n'

for i in range(len(typelist)):

print '\t',typelist[0],typelist[1],'\t',

if i % 2 ==1 : print '\n'

if flag==0:

print '\n'+50*'='+'\n\t下面是轉(zhuǎn)辦單位的分類\n'+50*'='

for i in range(len(deptlist)):

print '\t',deptlist[0],deptlist[1],'\t',

if i % 2 ==1 : print '\n'

finally:

xls.Quit()

raw_input('\n\n'+50*'='+'\n請輸入回車鍵退出程序!')

print '正在退出程序,請稍等。。。'

希望本文所述對大家的Python程序設(shè)計有所幫助。

希望與廣大網(wǎng)友互動??

點此進行留言吧!

總結(jié)

以上是生活随笔為你收集整理的python对excel表统计视频教程_Python实现对excel文件列表值进行统计的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。