from files import ScanFile
import pandas as pd
from sqlalchemy import create_engine
def do_csv():
engine = create_engine('mysql+pymysql://root:root@localhost:3306/test')
dir = r"D:\ext.yucaixiang\Desktop\202005-202012购酒险数据"
scan = ScanFile(dir)
subdirs = scan.scan_subdir()
files = scan.scan_files()
print(files)
for file in files:
print(file)
df = pd.read_csv(file, encoding='gbk', skiprows=0)
df.to_sql('jdaz0002', engine, index=False, if_exists='replace')
print('Read from and write to Mysql table successfully!')
def do_excwl():
engine = create_engine('mysql+pymysql://root:root@localhost:3306/test')
dir = r"D:\ext.yucaixiang\Desktop\202005-202012购酒险数据"
scan = ScanFile(dir)
subdirs = scan.scan_subdir()
files = scan.scan_files()
print(files)
for file in files:
print(file)
df = pd.read_excel(file)
df.to_sql('jdaz0002', engine, index=False, if_exists='append')
print('Read from and write to Mysql table successfully!')
python 读取excel和CSV 并保存到mysql数据库
最新推荐文章于 2023-02-15 16:16:01 发布