eng = pymysql.connect(host='localhost', user='root', password='mysql', database='')
sql = 'SELECT * FROM tpco'
print('# ---- start to query -------- #')
df1 = pd.read_sql(sql, eng)
print('# ---- finish query -------- #')
# 清洗数据
shuffled = df1.sample(frac=1)
# 将数据等分为200份
results = np.array_split(shuffled, 200)
i = 0
# 循环保存数据,这里的part的类型是dataframe
for part in tqdm(results):
name = '200_' + str(i) + '.csv'
path = 'csv_200/' + name
print(type(part))
part.to_csv(path)
i += 1