import pandas as pd
from sqlalchemy import create_engine
conn = create_engine(f'{self.db_engine}://{self.db_user}:{self.db_password}@{self.db_host}:{self.db_port}/{self.db_database}')
# 将 dataframe 写入数据库
df = ...
df.to_sql('table_name', conn, schema='db_schema', if_exists='replace', index=False)
# 查库
pd.read_sql(f'select * from db_schema.table_name', con=conn)
上一篇

2023-04-16
下一篇

2023-04-16