1,使用的工具是Visual Studio Code
2,本地有python3的环境,且安装相应的模块
如果没有安装 cmd 下面使用如下命令
pip install -i Simple Index 库名
pip install -i Simple Index pandas
pip install -i Simple Index sqlalchemy
pip install -i Simple Index pythonsql
脚本如下:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'nishi'
import pandas as pd
from sqlalchemy import create_engine
csv_data = pd.read_csv('D:\\任务\\AI\\python\\es_data_dev_SndOptPower_2022-07-05-12-52-36.csv') # 读取训练数据 目录
#print(csv_data.shape) # (189, 9)
print(csv_data.iloc[:,:5]) # (189, 9)
engine = create_engine('mysql+pymysql://root:root@数据库名:3306/ai', encoding="utf8")
#数据库账号密码
csv_data.to_sql(
name = 'es_data_dev_sndoptpower1',
con = engine,
index = False,
if_exists = 'append'
)