import pandas as pd
import pymysql
import numpy as np
conn2=pymysql.connect(host = '' ,user = '' ,passwd='' ,port= ,db='',charset='utf8')
cur = conn2.cursor()
search = "select id ,bulk_modulu,shear_modulus,hpoisson_rate,jghlx_else1,bheat_capa,rswell_modu from workafterlixue where created BETWEEN'2021-06-01 10:59:15' AND '2021-07-01 10:59:15'"
cur.execute(search)
getdata = cur.fetchall()
cur.close()
print(getdata)
import csv
tableName = "workafterlixue"
expfile = "{}.csv".format(tableName) ## 输出csv文件
df = pd.DataFrame(list(getdata))
labels = ['id', 'bulk_modulu','shear_modulus','hpoisson_rate','jghlx_else1','bheat_capa','rswell_modu']
expfile = open(expfile, 'w', encoding='utf-8',newline='') # a:表示追加
writer = csv.writer(expfile)
writer.writerow(list(labels))
writer.writerows(np.array(df))
expfile.close()
python 爬取 mysql 数据并转成csv
最新推荐文章于 2022-11-25 14:57:08 发布