python 實現讀取一個excel多個sheet表並合並的方法


如下所示:

import xlrd

import pandas as pd
from pandas import DataFrame
  
DATA_DIR = 'D:/'
 
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)):
 
# skiprows=2 忽略前兩行
df = pd.read_excel(excel_name, sheet_name = i, skiprows = 2 , index = False , encoding = 'utf8' )
df_28 = df_28.append(df)
 
# 去除缺省值
df_28 = df_28.dropna()
df_28 = df_28.reset_index(drop = True )
print ( len (df_28))


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM