Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

importing database in dataframe using sqlalchemy

import sqlalchemy as db
import pandas as pd
engine = db.create_engine('sqlite:///traffic.sqlite') # just for example

# AFTER those 3 lines, there are several ways

# one way to do it by using context manager
with engine.connect() as con:
	dbqu=con.execute("SELECT * FROM employee")
    df=pd.DataFrame(dbqu.fetchall())
    
# another alternate way is pretty simple by using pandas
df= pd.read_sql_query("SELECT * FROM employee", engine)

# the last tedious way--
con=engine.connect()
dbqu=con.execute("SELECT * FROM employee")
df=pd.DataFrame(dbqu.fetchall())
con.close() # WARNING- don't forget to close the connection in this last format
Comment

PREVIOUS NEXT
Code Example
Python :: view all columns in pandas dataframe 
Python :: print out a name in python 
Python :: gematria python 
Python :: query with condition django 
Python :: pandas get value not equal to 
Python :: dataclass default list 
Python :: Kill python background process 
Python :: append dictionary to list python 
Python :: python list transpose 
Python :: spam python 
Python :: How to take total count of words in the list python 
Python :: append python 
Python :: text widget get tkinter 
Python :: pandas change dtype 
Python :: intersection() Function of sets in python 
Python :: how to cerate a bar chart seaborn 
Python :: how to run python module every 10 sec 
Python :: circular list python 
Python :: remove all rows with at least one zero pandas 
Python :: aws lambda environment variables python 
Python :: how to add item to a list python 
Python :: python sort array by value 
Python :: progress bar python 
Python :: numpy int64 to int 
Python :: how to print a column from csv file in python 
Python :: matplotlib animate 
Python :: how to install pyinstaller 
Python :: Python Roman to Integer method 2 
Python :: remove tab space from string in python 
Python :: how to sort a list descending python 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =