Answers for "sqlalchemy create database sqlite"

1

use sqlalchemy to create sqlite3 database

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())
Posted by: Guest on August-21-2021

Code answers related to "sqlalchemy create database sqlite"

Python Answers by Framework

Browse Popular Code Answers by Language