python提取EXCEL 合併成新EXCEL

安裝操作環境:

安裝:

python -m pip install jupyter notebook -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install --upgrade pip -i https://pypi.douban.com/simple/

pip install --user pandas -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install xlrd  -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install openpyxl  -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com

 

cd C:\Users\chair\AppData\Local\Programs\Python\Python38\Scripts

import pandas as pd
import os
data=pd.DataFrame()
dir="D:/nevwork/"
filenames=os.listdir(dir)
for name in filenames:
      file=pd.ExcelFile("D:/nevwork/"+name)
      for i in file.sheet_names;
           if "日記賬" in i
              df=pd.read_excel("D:/nevwork/"+name,sheet_name=i,skiprows=4,usecols="C:F")
              condition=df["月份"].str.startswith("2月")
              s1=df[condition]
              data=pd.concat([data,s1])
data.to_excel("D:/newwork/合併完成.xlsx")

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章