中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

喬拓云智能建站官網(wǎng)登錄入口廈門關(guān)鍵詞排名提升

喬拓云智能建站官網(wǎng)登錄入口,廈門關(guān)鍵詞排名提升,襄陽作風(fēng)建設(shè)年活動網(wǎng)站,做我的世界背景圖的網(wǎng)站Python處理Excel文件并與數(shù)據(jù)庫匹配做拼接 需求:Python處理Excel中數(shù)據(jù)并于數(shù)據(jù)庫交互匹配得到賬號信息等其他操作 Python實現(xiàn) import os import pandas as pd import pymssql import warnings import time# 提取速率函數(shù) def extract_broadband_speed(speed):if…

Python處理Excel文件并與數(shù)據(jù)庫匹配做拼接

需求:Python處理Excel中數(shù)據(jù)并于數(shù)據(jù)庫交互匹配得到賬號信息等其他操作

Python實現(xiàn)

import os
import pandas as pd
import pymssql
import warnings
import time# 提取速率函數(shù)
def extract_broadband_speed(speed):if pd.notnull(speed) and 'M' in str(speed):return str(speed).split('M')[0] + 'M'else:return ''# 拼接工單標題函數(shù)
def concatenate_with_dash(row):product_type = row.get('產(chǎn)品類型')workorder_type = row.get('工單類型')access_type = row.get('方式')broadband_speed = row.get('速率提取')if workorder_type in ['改', '其他']:if product_type == '寬帶':return f"{product_type}-{broadband_speed}-{access_type}-{workorder_type}"else:return f"{product_type}-{workorder_type}"elif product_type == '寬帶':return f"{product_type}-{broadband_speed}-{access_type}-{workorder_type}機"else:return f"{product_type}-{workorder_type}機"# 清空文件夾下的所有Excel文件數(shù)據(jù)只保留一個表頭數(shù)據(jù)
def clear_data_in_excel_files(current_directory):# 獲取當(dāng)前文件夾下的所有 Excel 文件files = [file for file in os.listdir(current_directory) if file.endswith('.xls') or file.endswith('.xlsx')]# 遍歷所有 Excel 文件并清空除第一行表頭外的數(shù)據(jù)for file in files:file_path = os.path.join(current_directory, file)  # 獲取文件的路徑df = pd.read_excel(file_path)  # 讀取 Excel 文件df = df.head(0)  # 保留第一行表頭df.to_excel(file_path, index=False, header=True)  # 將清空后的數(shù)據(jù)覆蓋寫入原 Excel 文件print(f"成功清空文件: {file}")print("成功清空所有 Excel 文件的除第一行表頭外的數(shù)據(jù)")def main():start_time = time.time()print("程序開始時間:", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time)))warnings.filterwarnings('ignore')  # 忽略警告# 數(shù)據(jù)庫連接信息server = '127.0.0.1'database = 'YD'username = 'sa'password = 'xyz@1234560'conn = pymssql.connect(server, username, password, database)# 執(zhí)行 SQL 查詢sql_query = '''SELECT 地市, 人員名稱, [賬號]FROM [ZHB]'''# 讀取數(shù)據(jù)庫數(shù)據(jù)data = pd.read_sql(sql_query, conn)data.rename(columns={'人員名稱': '處理人'}, inplace=True)# 獲取當(dāng)前工作目錄current_directory = os.getcwd()# 獲取當(dāng)前文件夾下的所有文件files = [file for file in os.listdir(current_directory) if file.endswith('.xls')]# 統(tǒng)計各個工單類型的總數(shù)workorder_count = {}for file in files:file_path = os.path.join(current_directory, file)  # 獲取文件的路徑df0 = pd.read_excel(file_path)  # 讀取 Excel 文件df0['速率提取'] = df0['速率'].apply(extract_broadband_speed)df0['用戶品質(zhì)-NEW'] = df0['速率提取'].apply(lambda x: '千兆' if x == '1000M' else '普通品質(zhì)')df0['產(chǎn)品工單類型合并'] = df0.apply(concatenate_with_dash, axis=1).str.replace('裝機', '新裝')# 修改“區(qū)域?qū)傩浴绷忻麅?nèi)容,含有城市和鄉(xiāng)鎮(zhèn)的替換為城鎮(zhèn)df0['區(qū)域-修改'] = df0['區(qū)域'].fillna('城鎮(zhèn)').str.replace('城市', '城鎮(zhèn)').str.replace('鄉(xiāng)鎮(zhèn)', '城鎮(zhèn)')# 修改“是否沿街”列名中有內(nèi)容的改成是,沒有內(nèi)容的改成否df0['是否沿街-修改'] = df0['沿街'].apply(lambda x: '是' if pd.notnull(x) else '否')df0['開始時間'] = df0['預(yù)約上門時間'].apply(lambda x: str(x).split(' ~ ')[0].strip() if isinstance(x, str) else '')df0['結(jié)束時間'] = df0['預(yù)約上門時間'].apply(lambda x: str(x).split(' ~ ')[-1].strip() if isinstance(x, str) else '')print(f"成功讀取文件: {file}")# 統(tǒng)計各個工單類型的總數(shù)for workorder_type in df0['產(chǎn)品類型']:workorder_count[workorder_type] = workorder_count.get(workorder_type, 0) + 1# 使用 merge 進行數(shù)據(jù)匹配merged_df = pd.merge(df0, data[['地市', '處理人', '賬號']], on=['地市', '處理人'], how='left')# 打印每個產(chǎn)品類型的相關(guān)信息for idx, (product_type, group_data) in enumerate(merged_df.groupby('產(chǎn)品類型')):print(f"產(chǎn)品類型 {idx + 1}: {product_type}")filtered_data = merged_df[merged_df['產(chǎn)品類型'].isin(['ZW', 'TR'])]filtered_data.to_excel("源文件/ZW_TR數(shù)據(jù)合并.xlsx", index=False)print("成功將產(chǎn)品類型為 ZW_TR數(shù)據(jù)合并.xlsx")product_types = ['云', '門鈴', '喇叭', 'HM']hm_data = merged_df[merged_df['產(chǎn)品類型'].isin(product_types)]hm_data.to_excel("源文件/HM_數(shù)據(jù).xlsx", index=False)# 將其它類型的數(shù)據(jù)分別保存到不同文件中other_data = merged_df[~merged_df['產(chǎn)品類型'].isin(['ZW', 'TR', '云', '門鈴', '喇叭', 'HM'])]for product_type, group_data in other_data.groupby('產(chǎn)品類型'):file_name = f"源文件/{product_type}_數(shù)據(jù).xlsx"group_data.to_excel(file_name, index=False)print(f"成功將產(chǎn)品類型為 {product_type} 的數(shù)據(jù)導(dǎo)出到文件 {file_name}")print("成功將數(shù)據(jù)庫查詢結(jié)果匹配并拆分業(yè)務(wù)導(dǎo)出為Excel文件")# 遍歷目標文件夾下的所有 Excel 文件target_folder = '數(shù)據(jù)庫字段/'clear_data_in_excel_files(target_folder)for file_name in os.listdir(target_folder):file_path = os.path.join(target_folder, file_name)if file_name.endswith('.xlsx'):source_file_path = os.path.join('源文件/', file_name)if os.path.isfile(source_file_path):df_source = pd.read_excel(source_file_path)df_target = pd.read_excel(file_path)for source_col, target_col in [('施工單編碼', '編碼'),('施工單編碼', 'boss號'),('產(chǎn)品工單類型合并', '工單標題'),('市', '市'),('縣', '縣'),('接入方式', '接入方式'),('受理時間', '受理時間'),('派單時間', '派單時間'),('歸檔時間', '歸檔時間'),('預(yù)約上門時間', '前臺預(yù)約時間'),('處理人', '施工人員'),# 字段添加('寬帶速率', '寬帶速率'),('寬帶套餐資費', '套餐信息'),('開始時間', '預(yù)約上門時間'),('區(qū)域-修改', '區(qū)域'),('是否沿街-修改', '沿街商鋪'),('用戶品質(zhì)-NEW', '品質(zhì)'),]:if source_col in df_source.columns and target_col in df_target.columns:df_target[target_col] = df_source[source_col]if 'ZW_TR數(shù)據(jù)合并.xlsx' in source_file_path:if 'ZW資費' in df_source.columns and '信息' in df_target.columns:df_target['信息'] = df_source['ZW資費']df_target.to_excel(file_path, index=False)print(f"成功將字段復(fù)制到文件 {file_path} 中")# 打印工單類型的總數(shù)print("產(chǎn)品類型總數(shù):")for workorder_type, count in workorder_count.items():print(f"{workorder_type}: {count}")end_time = time.time()print("程序結(jié)束時間:", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time)))run_time = end_time - start_timeprint("程序運行耗時:%0.2f" % run_time, "s")# 提示用戶按任意鍵退出程序input("按任意鍵退出程序")if __name__ == "__main__":main()
http://www.risenshineclean.com/news/52540.html

相關(guān)文章:

  • 網(wǎng)站ie不兼容如何開發(fā)網(wǎng)站
  • 唐山市住房城鄉(xiāng)建設(shè)部網(wǎng)站主頁營業(yè)推廣策劃
  • 朝陽網(wǎng)站建設(shè)seo是什么技術(shù)
  • 網(wǎng)站建設(shè)好的圖片seo優(yōu)化專員工作內(nèi)容
  • 網(wǎng)站建設(shè)的具體過程網(wǎng)絡(luò)營銷崗位職責(zé)和任職要求
  • wordpress搜索引擎源碼深圳seo招聘
  • 做配音任務(wù)的網(wǎng)站百度搜索推廣費用
  • 免費雙語網(wǎng)站模板如何把網(wǎng)站推廣
  • jsp網(wǎng)站購物車怎么做seo外鏈工具軟件
  • 濟南個人網(wǎng)站建設(shè)系統(tǒng)優(yōu)化軟件哪個最好的
  • 資訊網(wǎng)站模板周口seo公司
  • 物流網(wǎng)站建設(shè)與管理長沙網(wǎng)站策劃
  • 網(wǎng)上備案查詢seo自然搜索優(yōu)化排名
  • wordpress怎么新建欄目seo推廣排名公司
  • 在哪個網(wǎng)站做流程圖比較好看軟件開發(fā)網(wǎng)
  • 網(wǎng)站建設(shè)采購公告友情鏈接網(wǎng)
  • 基于web的網(wǎng)站開發(fā)技術(shù)路線seo優(yōu)化的基本流程
  • 做網(wǎng)上推廣網(wǎng)站免費制作網(wǎng)站app
  • 分享類網(wǎng)站源碼軟文營銷的步驟
  • 洞口做網(wǎng)站推薦seo優(yōu)化服務(wù)商
  • 在家做兼職的比較靠譜的網(wǎng)站青島網(wǎng)站建設(shè)制作
  • WordPress文章生成海報代碼seo推廣策略
  • 好的專題網(wǎng)站鏈接生成器
  • 做兼職的那個網(wǎng)站靠譜google國際版入口
  • 網(wǎng)上開店營業(yè)執(zhí)照怎么辦理百度網(wǎng)站優(yōu)化排名
  • 長沙做網(wǎng)站哪里好2021小說排行榜百度風(fēng)云榜
  • 全flash網(wǎng)站制作優(yōu)質(zhì)友情鏈接
  • 網(wǎng)站宣傳視頻瑞金網(wǎng)絡(luò)推廣
  • 佛山免費網(wǎng)站制作免費發(fā)布信息
  • 尋找網(wǎng)站優(yōu)化公司seo網(wǎng)絡(luò)推廣招聘