如下所示:
1
2
3
4
5
|
import xlrd import pandas as pd from pandas import DataFrame DATA_DIR = 'E:/' |
1
2
3
4
5
6
7
8
9
10
11
|
excel_name = '%s2017.xls' % DATA_DIR wb = xlrd.open_workbook(excel_name) # print(wb) # 获取workbook中所有的表格 sheets = wb.sheet_names() # print(sheets) # 循环遍历所有sheet df_28 = DataFrame() for i in range ( len (sheets)): |
1
2
3
|
# skiprows=2 忽略前两行 df = pd.read_excel(excel_name, sheet_name = i, skiprows = 2 , index = False , encoding = 'utf8' ) df_28 = df_28.append(df) |
1
2
3
4
|
# 去除缺省值 df_28 = df_28.dropna() df_28 = df_28.reset_index(drop = True ) print ( len (df_28)) |
以上这篇python 实现读取一个excel多个sheet表并合并的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_34218221/article/details/78974541