Q. You have a database on MySQL namely school having three tables in it - Student, Subject, Teacher. Write a program to store these tables in three dataframes.


Answer :-

import mysql.connector as a
db=a.connect(user='root',passwd='0000000000' ,host='localhost',database='school')

import pandas as pd
tables=['student','subject','teacher']
df=pd.read_sql(f'select * from {tables[0]}',db)
df1=pd.read_sql(f'select * from {tables[1]}',db)
df2=pd.read_sql(f'select * from {tables[2]}',db)

print(df)
print(df1)
print(df2)

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post