日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CM资料下载操作

發布時間:2024/3/24 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CM资料下载操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 將apply_id寫入txt,每個txt存50條
  • def apply_id_txt(l,path,channel):"""l:列表,里面元素為字符串形式path:存放txt路徑channel:渠道:車貸、個貸..."""l_new =[]for i in l:l_new.append(i+'\n')for i in range(np.ceil(len(l)/50).astype('int')):l_s = l_new[i*50:(i+1)*50]l_s[-1] = l_s[-1].replace('\n','')with open(os.path.join(path,'{}_{}.txt'.format(channel,(i+1))),'w') as f:f.write('LOAN_NUMBER\n')f.writelines(l_s)# ---------------------------------------------------------- # l要先區分車貸和個貸 path = r'C:\Users\Administrator\Desktop\apply_id' d = pd.read_excel(r'C:\Users\Administrator\Desktop\datamatch.xlsx') l = d['apply_id'].astype('str).tolist() apply_id_txt(l,path,'車貸')
  • 下載解壓后,去掉最外層文件夾
  • # 解壓后匯總到一個文件夾 path = r'C:\Users\Administrator\Desktop\cm資料-學兵 - 備份' for file in os.listdir(path):try:for sub_file in os.listdir(os.path.join(path,file)):shutil.move(os.path.join(os.path.join(path,file),sub_file),os.path.join(path,sub_file))shutil.rmtree(os.path.join(path,file))except:print('錯誤')
  • 文件夾重命名+分組
  • def cm_rename(path,match_data): """path:存放cm文件夾路徑match_data:DataFrame形式,包含:apply_id,transport_id,mortgagor_name,dept_name,product_name,apply_submit_time等"""# 統計一級文件夾下哪些是空文件夾n =[]for file in os.listdir(path):if len(os.listdir(os.path.join(path,file))) == 0:n.append(file) # no_cm = pd.DataFrame(np.array(n).reshape(len(n),1),columns=['apply_id']) # no_cm.to_excel(os.path.join(path,'空文件夾.xlsx',encoding='gbk'))# 根據apply_id 匹配 transport_id重命名文件夾dmap = match_data.copy()dmap['concat'] = dmap.transport_id.astype('str') + "-" + dmap.mortgagor_name + "-" + dmap.dept_namename_match = [*zip(dmap.apply_id.astype('str').tolist(),dmap.concat.tolist())]for old_name,new_name in name_match:try:os.rename(os.path.join(path,old_name),os.path.join(path,new_name))except FileNotFoundError as e:print('重命名:',e)# 刪除空一級文件夾for file in os.listdir(path):if len(os.listdir(os.path.join(path,file))) == 0:shutil.rmtree(os.path.join(path,file))# 將image文件下文件移到上一層文件夾 并刪除image文件夾for file in os.listdir(path):try:for png in os.listdir(os.path.join(os.path.join(path,file),'image')):shutil.move(os.path.join(os.path.join(os.path.join(path,file),'image'),png),os.path.join(os.path.join(path,file),png))shutil.rmtree(os.path.join(os.path.join(path,file),'image'))except:print('將image文件下文件移到上一層文件夾錯誤')n_folder = len(os.listdir(path))# 按營業部名稱dept_name分組for file in os.listdir(path):name = file.split('-')[3] # 取營業部名稱 if not os.path.exists(os.path.join(path,name)):os.makedirs(os.path.join(path,name))shutil.move(os.path.join(path,file),os.path.join(path,name))no_cm = match_data[match_data.apply_id.isin(n)]no_cm.apply_id = no_cm.apply_id.astype('str')no_cm.to_excel(os.path.join(path,'空文件夾清單.xlsx'),encoding='gbk',index=False)return print('空文件:{}個\n有文件:{}個'.format(len(n),n_folder)) # ------------------------------------------------------ path = r'C:\Users\Administrator\Desktop\cm資料' d = pd.read_excel(r'C:\Users\Administrator\Desktop\datamatch.xlsx') cm_rename(path,d)

    【參考資料】
    1、Python中os包的用法
    2、Python 文件夾重命名的兩種方法
    3、Python 將列表數據寫入文件(txt, csv, excel)

    總結

    以上是生活随笔為你收集整理的CM资料下载操作的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。