將一個文件夾的表格修改完放在另一個文件夾
import pandas as pd,os
from pandas import DataFrame
# 修改表格
def updateExel(path,out_path,name):
print('開始加載',os.path.join(path,name))
data = pd.read_excel(os.path.join(path,name),sheet_name='sheet1')
df = DataFrame(data)
for index,row in df.iterrows():
product_id1 = row['product_id'].split('.h')[0]
product_id2 = product_id1.split('-')
df.at[index,'product_id'] = product_id2[-2] + '-' + product_id2[-1]
df.to_excel(os.path.join(out_path,name), sheet_name='sheet1', index=False, header=True)
if __name__ == '__main__':
path = 'C:\\Users\\SHEIN\\Desktop\\zalando-1'
out_path = 'C:\\Users\\SHEIN\\Desktop\\zalando-2'
for file in os.listdir(path):
if file.endswith('.xls'):
updateExel(path,out_path,file)