python后端将svc文件数据读入数据库具体实现
生活随笔
收集整理的這篇文章主要介紹了
python后端将svc文件数据读入数据库具体实现
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
如何用python將svc文件的數(shù)據(jù)讀入到MySQL數(shù)據(jù)庫里,在此直接上代碼了,感興趣的朋友可以貼代碼測試:
import pandas as pd import os from sqlalchemy import create_engine # 初始化數(shù)據(jù)庫連接,使用pymysql模塊 # MySQL的用戶:root, 密碼:123456, 端口:3306,數(shù)據(jù)庫中已存在的數(shù)據(jù)庫名:python1 engine = create_engine(r'mysql+pymysql://root:123456@localhost:3306/python1') def write_sql(name,data=pd.DataFrame()):global enginedata.to_sql(name,engine,if_exists='fail',index=False)# 數(shù)據(jù)路徑(csv文件) path = r'D:\My_software2\mysql\mysql_workspace\teacher_code\數(shù)據(jù)庫\僅用于學(xué)習(xí)測試數(shù)據(jù)' # 表示讀取path下的文件夾‘僅用于學(xué)習(xí)測試數(shù)據(jù)’的第一條數(shù)據(jù), # 讀取全部可將后面的[0]去掉,下面的[name_list]---》變成name_list,item.split('.')[0]---》item.split('.') name_list = os.listdir(path)[0]for item in [name_list]:name = item.split('.')[0]path_ = os.path.join(path,item)print(path_)with open(path_, 'rb') as f:data = pd.read_csv(f, sep=',', header=0, index_col=None, na_values=['NULL'], na_filter=True, encoding='utf8')write_sql(name,data)print('完成!')?
轉(zhuǎn)載于:https://www.cnblogs.com/Dark-fire-liehuo/p/9819232.html
總結(jié)
以上是生活随笔為你收集整理的python后端将svc文件数据读入数据库具体实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何准备性能测试数据
- 下一篇: LOD优化策略通篇