python關於利用excel修改檔名

2021-10-12 21:18:05 字數 1206 閱讀 6995

關於利用excel修改檔名

這個檔案最後修改完會儲存到,這個py程式所在的資料夾,執行結果會有提示,

import os,sys

from openpyxl import load_workbook

#讀取**

wb=load_workbook(r"c:\users\dell\desktop\新建 microsoft excel 工作表.xlsx"

)#**檔名

sheet=wb[

"sheet1"

]#表名

list1=sheet.columns # 按列獲取單元格(cell物件)

#print("最大行:".format(sheet.max_row)) #數**最大行

#print("最大行:".format(sheet.max_column)) #數**最大列

#讀取檔案

defreadname()

: name = os.listdir(r"c:\users\dell\desktop\新建資料夾"

)#這個地方是舊檔案所在的資料夾

return name

fileold=readname(

)dict1=

list

(range(2

,32))

#定義第幾行到第幾行

for dict2,a in

zip(dict1,fileold)

: res = sheet.cell(dict2,1)

.value #列印從dict上定義的從第幾行到第幾行,的第7列

print

(res)

print

(a) old=r"c:\users\dell\desktop\新建資料夾"

+"\\"

+a #這個地方是舊檔案需要在前邊新增檔案路徑,新名字不用

new=res

os.renames(old,new)

# 遞迴地對目錄進行更名,也可以對檔案進行更名。os.renames(old, new)

print

("目錄為: %s"

%os.listdir(os.getcwd())

)

報錯

還有這個如果py所在的資料夾有重複的檔案名字會報錯,這個時候把重複檔名的檔案從這個資料夾清理掉就可以(刪掉或移動)

利用Python處理Excel資料

資料清洗 資料預處理 資料提取 資料篩選 資料彙總 資料統計 import pandas as pd import numpy as np import matplotlib.pyplot as plt from datetime import datetime from pandas import...

利用Python處理Excel資料

目錄 資料清洗 資料預處理 資料提取 資料篩選 資料彙總 資料統計 import pandas as pd import numpy as np import matplotlib.pyplot as plt from datetime import datetime from pandas imp...

python統計excel利用pandans的分組

python統計excel利用pandans的分組,其中還用列表資料求差集 csv資料結構 有三個按照日期統計的csv 需要統計出這三張csv按照areaid缺少的type和bdtype 其中type 1,2,3,4 bdtype 1,3,4 原始碼如下 第一步資料初步處理刪除非必須列 coding...