import pandas as pd
df=pd.read_excel('student.xlsx') # DataFrame created using student file
from sqlalchemy import create_engine,text
from sqlalchemy.exc import SQLAlchemyError
path="sqlite:///my_data.db" # create a SQLite database in google colab session storage
my_conn = create_engine(path)
my_conn=my_conn.connect() # connection is established
try:
result = my_conn.execute(text("select name from sqlite_master where type = 'table'"))
for row in result:
print(row) # Display all tables in SQLite database
except SQLAlchemyError as e:
error = str(e.__dict__['orig'])
print(error)
df.to_sql(con=my_conn,name='student') # create student table in sqlite database
try:
result = my_conn.execute(text("select name from sqlite_master where type = 'table'"))
for row in result:
print(row) # List all tables in our SQLite database
except SQLAlchemyError as e:
error = str(e.__dict__['orig'])
print(error)
('student',)
From student table, display records.
result = my_conn.execute(text("SELECT * FROM student"))
for row in result:
print(row) # display row from student table.
Use conditions to get matching records from SQLite database student table.
result = my_conn.execute(text("SELECT * FROM student WHERE mark > 80 AND class='Five'"))
for row in result:
print(row) # display row from student table.
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.