pandas和SQL数据分析实战视频教程

统计excel  C列 化学  和D列 补充申请  两个条件药品数量

程序优势在于批量统计,把参数写到excel里,行为单位

# -*- coding: utf-8 -*-

"""

Created on Thu Apr 7 08:38:51 2016

content内容必须是逗号分隔,例如'化药,中药'

用于统计excel--sheet---二级条件筛选的数据统计

算法:

1.读取所有excel内容,保存到二维列表中

2.二级筛选

@author: Administrator

"""

import csv,xlrd,os,openpyxl

#获取所有excel文件名

def Get_excelFileNames():

excelFiles_list=[]

for excelFilename in os.listdir('.'):

if excelFilename.endswith('.xlsx') or excelFilename.endswith('.xls'):

excelFiles_list.append(excelFilename)

return excelFiles_list

#获取一个excel内首页表格

def Get_sheet1_from_oneExcel(excelFileName):

wb=xlrd.open_workbook(excelFileName)

sheet=wb.sheets()[0]

return sheet

#获取excel的首页信息,去除首行

def Get_sheet1_Data_NoFirstLine(excelFileName):

sheet=Get_sheet1_from_oneExcel(excelFileName)

#获取表格行数和列数

highest_row=sheet.nrows

highest_column=sheet.ncols

sheet_data=[]

for rowNum in range(1,highest_row):

#获取行数据

rowData=sheet.row_values(rowNum)

sheet_data.append(rowData)

return sheet_data

#把csv文档内容转换成一个列表,不包括首行

def Read_CsvRows_noFirstLine(csvFilename):

csvRows = []

csvFileObj = open(csvFilename)

readerObj = csv.reader(csvFileObj)

for row in readerObj:

if readerObj.line_num == 1:

continue # skip first row

csvRows.append(row)

csvFileObj.close()

return csvRows

def one_excel_column_statistic(csv_row):

#csv特定行包含excel名字,sheet名,列,搜索内容

excelFilename=csv_row[0]

#print("excelFilename",excelFilename)

sheetName=csv_row[1]

#print("sheetName",sheetName)

column=int(csv_row[2])

#print("column",column)

content=csv_row[3]

#'化药,中药'必须转换为['化药', '中药'],否则无法遍历

content_list=content.split(",")

wb=xlrd.open_workbook(excelFilename)

sheet=wb.sheet_by_name(sheetName)

#获取excel指定列的类容

column_content_list=sheet.col_values(column)

#print("column_content_list",column_content_list)

number=0

for i in content_list:

count=column_content_list.count(i)

number+=count

print("excel文件名",excelFilename)

print("统计内容:",content)

print("数量:",number)

print("-"*20)

return number

def all_excel_column_statistic(csvFileName):

csv_content=Read_CsvRows_noFirstLine(csvFileName)

for csv_row in csv_content:

one_excel_column_statistic(csv_row)

def second_condition_statistic(csv_row):

count=0

excelFileName=csv_row[0]

sheet_data=Get_sheet1_Data_NoFirstLine(excelFileName)

Condition1=csv_row[2].split(',')[1]

Column1_letter=(csv_row[2].split(',')[0])

index1=column_letter_index_convert(Column1_letter)

Condition2=csv_row[3].split(',')[1]

Column2_letter=(csv_row[3].split(',')[0])

index2=column_letter_index_convert(Column2_letter)

for rowData in sheet_data:

if rowData[index1]==Condition1 and rowData[index2]==Condition2:

count+=1

print("excel文件名",excelFileName)

print("统计内容:",Condition1+">"+Condition2)

print("数量:",count)

print("-"*20)

return count

def all_second_condition_statistic(csvFileName):

csvRows=Read_CsvRows_noFirstLine(csvFileName)

for csv_row in csvRows:

second_condition_statistic(csv_row)

#excel列的

def column_letter_index_convert(letter):

list_letter_index=[["A",0],["B",1],["C",2],["D",3],["E",4],["F",5],["G",6],["H",7],["I",8],\

["J",9],["K",10],["L",11],["M",12],["N",13],["O",14],["P",15],["Q",16],["R",17],\

["S",18],["T",19],["U",20],["V",21],["W",22],["X",23],["Y",24],["Z",25]]

for i in list_letter_index:

if i[0]==letter.upper():

index=i[1]

return index

csvFileName="config.csv"

all_second_condition_statistic(csvFileName)

'''

excelFileName='1月.xlsx'

csv_row=['1月.xlsx', 'Sheet1', 'C,化药', '3,补充申请']

'''

print("问题反馈邮箱:231469242@qq.com")

print(" .-. ")

print(" \ \ ")

print(" \ \ ")

print(" 喵 喵 喵 | | ")

print(" | | ")

print(" /\---/\ _,---._ | | ")

print(" /^ ^ \,' `. ; ")

print(" ( O O ) ; ")

print(" `.=o=__,' \ ")

print(" / _,--.__ \ ")

print(" / _ ) ,' `-. `-. \ ")

print(" / ,' / ,' \ \ \ \ ")

print(" / / / ,' (,_)(,_) ")

print("(,; (,,) ")

var=input("enter anykey to quit")

python脚本自动统计excel_python脚本实现-excel二级统计相关推荐

  1. python扫雷脚本_利用 Python 实现 自动扫雷 小脚本

    原标题:利用 Python 实现 自动扫雷 小脚本 自动扫雷一般分为两种,一种是读取内存数据,而另一种是通过分析图片获得数据,并通过模拟鼠标操作,这里我用的是第二种方式.一.准备工作1.扫雷游戏 我是 ...

  2. php做引流脚本,自动引流脚本你知道是怎么实现的自动化引流?

    引流脚本是在今年兴起的一种火爆的引流方式,对此我相信大部分需要引流的朋友都不陌生.引流脚本引流的原理其实很简单:就是利用电脑编程制作一个小的脚本程序,这个脚本功能就是能够自动的到手机各大app里面去推 ...

  3. python按照日期筛选excel_Python玩转Excel:实现函数自动填充、数据排序

    工作中,大家经常会使用excel去处理数据以及展示,但是对于部分工作我们可以借助程序帮忙实现,达到高效解决问题的效果. 比如将接口返回的json解析并保存结果到excel中,按一定规律处理excel中 ...

  4. python自动更新excel_Python杀死了Excel|自动更新表格,告别繁琐

    大家好,又到了Python办公自动化专题. 今天我们讲解的案例是如何使用Python自动更新Excel表格,简单来说就是每天都会对Excel中多个sheet进行更新,需要操作完后可以用程序完成第一张s ...

  5. 利用Python实现自动扫雷小脚本

    自动扫雷一般分为两种,一种是读取内存数据,而另一种是通过分析图片获得数据,并通过模拟鼠标操作,这里我用的是第二种方式. 代码已上传至GitHub: https://github.com/chestnu ...

  6. excel多条件计数python_python脚本实现-excel二级统计

    pandas和SQL数据分析实战视频教程 统计excel C列 化学 和D列 补充申请 两个条件药品数量 程序优势在于批量统计,把参数写到excel里,行为单位 # -*- coding: utf-8 ...

  7. python扫雷脚本_利用Python实现自动扫雷小脚本

    自动扫雷一般分为两种,一种是读取内存数据,而另一种是通过分析图片获得数据,并通过模拟鼠标操作,这里我用的是第二种方式. 代码已上传至GitHub: https://github.com/chestnu ...

  8. c4d python sdk_C4D脚本自动接口完成脚本 Python Cinema 4D API auto completion (fake package)

    The combination of Eclipse and PyDev makes an excellent development environment for coding Cinema 4D ...

  9. python手游脚本自动采集_Python脚本结合UiAutomator自动化采集Activity的FPS

    前置条件 python调试环境 Eclipse(Version: Luna Release (4.4.0))+pydev(3.7.0) UiAutomator 准备一个用于滑动被测试APP的UiAut ...

最新文章

  1. 始于《将才》,而不止于将才
  2. Win8怎么查看IP地址
  3. 20应用统计考研复试要点(part15)--应用多元分析
  4. nginx配合python_人生苦短我用python[0x02] nginx与python结合
  5. MYSQL错误代码#1045 Access denied for user 'root'@'localhost'
  6. 基于 Tracing 数据的拓扑关系生成原理
  7. ga算法matlab,matlab遗传算法ga函数
  8. 如何快速开发一个支持高效、高并发的分布式ID生成器(二)
  9. Flask render_template
  10. 阿里云服务器18个数据中心测试IP地址以及测试方法
  11. oracle日期的sql,Oracle中一些和日期有关的SQL查询
  12. 转:POJ先做完这50题再说
  13. selenium java1.7_selenium-java(第一篇)
  14. .net 创建计划任务开机后自动以管理员身份启动运行 win7 ~ win10
  15. Java并发编程实战_Java并发编程实战
  16. Matplotlib折线图(绘图实例+代码详解)
  17. 排查oracle数据库服务是否启动
  18. iOS 调整图片尺寸和大小的两个方法
  19. 前端正则表达式指定邮箱域名匹配
  20. 强推win10损害用户利益?这锅微软不背

热门文章

  1. WPF使用Canvas绘制可变矩形
  2. C++ Primer 第10章 习题10.24
  3. PHP中foreach遍历循环的使用(两种用法)
  4. java--自动装箱,拆箱
  5. MVC原理及案例分析
  6. 信号时频图的横纵坐标对调
  7. java视频压缩 lz4_关于LZMA和LZ4压缩的疑惑解析
  8. python提取部分字符串三参数_python3 字符串属性(三)
  9. oci连接mysql_使用 OCILIB 连接并操作 Oracle 数据库
  10. python3.6配置环境变量_python安裝及环境变量配置