使用numpy进行工作簿中多个表的数据汇总

在Excel中工作簿2016.xlsx中有三个表,Sheet1,Sheet2,Sheet3,分别存有一点数据,现在要把三个表汇总到一张表中存入工作簿。

import pandas as pd
import xlrd
from pandas import DataFrame


#得到工作簿
wb = xlrd.open_workbook('2016.xlsx')

#工作簿中的表
sheets = wb.sheet_names()

#遍历表名,将表中的数据汇总到
total = DataFrame()#容器

for i in range(len(sheets)):
	df = pd.read_excel('2016.xlsx',sheetname=sheets[i],encoding='utf8',skiprows=0)
	print('数据维度:',df.shape)
	print('元素个数:',df.size)
	total = total.append(df)
print('total:',total)

# 保存到一个工作表中
wb = pd.ExcelWriter('new2016.xlsx')
total.to_excel(wb,'Sheet1')
wb.save()

猜你喜欢

转载自blog.csdn.net/hanh22/article/details/85879740