python自带数据sqlite3学习,pandas to jeson
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('sqlite:///foo.db', echo=True)
# 建表
#engine.execute("create table t1(id int,name varchar(20))")
#插入数据
engine.execute("insert into t1 values(2,'jack')")
# read sql
df = pd.read_sql('select * from t1',con=engine)
# to jesqon
df = df.applymap(lambda x:str(x).strip())
account_dict = df.to_json(orient="records", force_ascii=False)
print(account_dict)