将一个DataFrame随机拆分为几个较小的DataFrame并保存

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
上一篇:IfcDistributionPort


下一篇:MySQL异常 #SQLException: sql injection violation, part alway true condition not allow