Ans 10 :
we can use if_exists = ‘append’ argument to retain old data of table.
Syntax:
<dataframe_object>.to_sql( “table_name”, connection_object, if_exists = “append”)
Example:
df.to_sql(“book”, con, if_exists = “append”)
Ans 11 :
import pandas as pd
import mysql.connector as sqlt
con = sqlt.connect (host = “localhost”, user = “root”, passwd = “yourpassword” , database = “yourdatabasename”)
cursor = con.cursor()
qry = “select * from book;”
df = pd.read_sql(qry, con)
print(df)