import MySQLdb
import numpy as np
#get data from sql databases
class database():
def __init__(self):
self.conn = MySQLdb.connect(
host='127.0.0.1',
user='root',
passwd='sangomine',
port=3306,
db='original_data',
charset = 'utf8'
)
def train_x(self):
with self.conn:
cur = self.conn.cursor()
sql = 'SELECT * FROM train_x'
cur.execute(sql)
data = cur.fetchall()
data_arr = np.array(list(data)).reshape(-1,7)
cur.close()
return data_arr
def train_y(self):
with self.conn:
cur = self.conn.cursor()
sql = 'SELECT * FROM train_y'
cur.execute(sql)
data = cur.fetchall()
data_arr = np.array(
从sql数据库中提取table并转换成numpy格式数据输出
最新推荐文章于 2022-04-26 20:13:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)