数据分析--pandas--合并多个表的数据

场景描述:在工做中每每会须要咱们对数据进行统计分析,然而咱们拿到的数据有的时候会在多张表中存储着,这个时候就须要把多个表的数据汇总到一块儿。

Example
首先这是咱们看到的三张工做表
在这里插入图片描述web

import pandas as pd
from pandas import DataFrame
import xlrd#pip install xlrd

#打开工做簿
wb =xlrd.open_workbook('meal_order_detail.xlsx')

sheets = wb.sheet_names()
#源码解释sheet_names()
A list of the names of all the worksheets in the workbook file.
This information is available even when no sheets have yet been loaded.
工做簿文件中全部工做表的名称列表。
即便没有工做表,此信息也可用加载。
’‘’
print(sheets)

#总的数据容器
total = DataFrame()

#循环遍历全部sheet,汇总数据
for i in range(len(sheets)):
    data = pd.read_excel('meal_order_detail.xlsx',sheetname=i,index_col=False)
    print(data.shape[0])#<class 'pandas.core.frame.DataFrame'>
 #汇总数据
  total = total.append(data)
#
# print(total.shape)
#
# #保存到新的文件(承载汇合数据)
# writer = pd.ExcelWriter('output.xlsx')
# total.to_excel(writer,'Sheet1')
# writer.save()