Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

import database in python 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 :: add a button pyqt5 
Python :: virtual env python 2 
Python :: def function in python 
Python :: how to convert boolean type list to integer 
Python :: how to use cv2.COLOR_BGR2GRAY 
Python :: django create object with default today date 
Python :: pyserial read 
Python :: python how to remove item from list 
Python :: python multiline comment 
Python :: try except finally python 
Python :: multiple boxplots python 
Python :: how to make a multiple choice quiz in python with tkinter 
Python :: how to make addition in python 
Python :: geopandas change columns dtype 
Python :: how to use cos in python 
Python :: python num2words installation 
Python :: what is the difference between python 2 and 3 
Python :: python compare timestamps 
Python :: To visualize the correlation between any two columns | scatter plot graph 
Python :: how to add two list by zip function in python 
Python :: discord get bot profile picture 
Python :: python split paragraph 
Python :: python submit work to redis 
Python :: numpy randint 
Python :: python read file into variable 
Python :: np.zeros 
Python :: Convert two lists into a dictionary in python 
Python :: python play music 
Python :: python thread function 
Python :: python is inf 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =