python实现Excel工作簿和表单合并
来源:互联网 发布:linux下安装wine软件包 编辑:程序博客网 时间:2024/04/29 21:16
Created on Mon Mar 16 11:23:05 2015@author: admin"""# 分批次运行,先得到books, 再运行,利用print 来debugimport pandas as pdimport numpy as np import matplotlib as plimport oscount=0#ori_path='xx'ori_path='C:\Python27\data\sample'def get_xls_books(ori_path): # get target filename and dir of a path temp = list(os.walk(ori_path)) #tmp is list ,tmp[0]该目录文件路径和文件名, tmp[1]:子目录文件路径,文件名称 book_path=[] book_name=[] root=temp[0][0] for i in temp[0][2]: if os.path.splitext(i)[1] == '.xlsx': #splite filename obj_path=os.path.join(root,i) book_path.append(obj_path) book_name.append(os.path.splitext(i)[0]) return zip(book_path, book_name)def get_xls_sheets(obj_path): #get all sheets of a object path xls=pd.ExcelFile(obj_path) sheet_names=xls.sheet_names sheets=[xls.parse(i) for i in range(0,len(sheet_names)) ] # use parse can get dataframe saved into a list return zip(sheet_names,sheets)books=get_xls_books(ori_path) # book paths list#xls=pd.ExcelFile(books[0])#print xls.parse(0).columnsfor book in books: # this loop get a book bookname=book[1] bookpath=book[0] sheets=get_xls_sheets(bookpath) # get all sheets and names from book path for i in range(len(sheets)): #operate each sheet, is range(len) not len sheetname=sheets[i][0] name=bookname+'-'+sheetname+'.'+'csv' pd_sheet=sheets[i][1] # dataFrame cols=pd_sheet.columns pdf=pd_sheet[[cols[17],cols[18],cols[4],cols[6],cols[8],cols[10],cols[19],cols[16]]] # use emunerate function pdf.columns=['area','patch','wangdian','operator','custid','servid','servtype','is_identify'] # rename pdf1=pdf[pdf['is_identify']=='是'] #filter pdf2=pdf1.drop('is_identify',1) pdf2.to_csv(os.path.join(ori_path,name), header=None, index=None)
0 0
- python实现Excel工作簿和表单合并
- excel VBA合并工作簿
- 合并多个EXCEL工作簿
- 关于Excel下通过VBA实现工作簿文件下工作表的合并
- SSIS FOR EXCEL 多工作簿多工作表合并
- 批量合并excel工作表
- 使用XLRD包识别Excel工作表单元格颜色代码-python,excel,xlrd-...
- 使用VBA合并多个Excel工作簿
- 使用VBA合并多个Excel工作簿
- 使用python的xlrd和xlwt模块合并excel表格
- Python合并Excel表格(自动合并)
- poi 如何实现Excel合并单元格和设置内容
- 多个excel工作簿汇总,同一工作簿中sheets合并
- 通过VBA宏合并Excel工作表
- Excel合并工作表,加载宏
- 用java实现合并excel
- 在表单里使用excel工作表
- 如何破解Excel工作表单的密码
- 蓝桥杯 求圆面积+注意求pi的方法
- Libevent(3)— 基础库
- E+H电磁流量计|E+H电磁流量计测量系统
- opencv之提取截获图像
- win7配置apche,php,mysql
- python实现Excel工作簿和表单合并
- 使用C模拟ATM练习switch..case用法
- (转)程序是怎么在内存中存储的
- POJ-2115-C Looooops 解题报告
- 激光雷达学习笔记(四)定位
- iOS App 中嵌入应用商店
- ESP8266入门指南——实现PC与模块通信
- Libevent(4)— Bufferevent
- Spring事务与自定义多线程陷阱