📅  最后修改于: 2022-03-11 14:47:00.351000             🧑  作者: Mango
from sqlalchemy import create_engine
import pandas as pd
# creates an engine for a database in current directory
engine = create_engine('sqlite:///yourDatabaseName.sqlite3')
# creates a dataframe in memory
df = pd.DataFrame({'tablename' : ['Data 1', 'Data 2', 'Data 3']})
# stores the dataframe as a table in the database
df.to_sql('tablename', con=engine)
# queries the table and stores the results in another dataframe
dfOne = pd.read_sql_table('tablename', engine)
# or you can create a custom sql query and store the results in a dataframe
dfTwo = pd.DataFrame(engine.execute("SELECT * FROM tablename").fetchall())