Articles → Pandas → to_sql function in pandas

to_sql function in pandas






Purpose





Example


import pandas as pd
from sqlalchemy import create_engine

engine = create_engine("sqlite:///c:\sqlite\SchoolDB.db")

df = pd.DataFrame([[3,'Test']])
engine.connect()

# Inserting data in table
df.to_sql("Departments", engine)

print("record inserted")

# Reading data
df = pd.DataFrame()
df = pd.read_sql('select * from Departments', con=engine)

print(df)



Output



Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, June 05, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250