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


Picture showing the output of to_sql function in pandas
Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250