Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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())
 
PREVIOUS NEXT
Tagged: #sqlalchemy #create #database
ADD COMMENT
Topic
Name
3+1 =