Informatics Practices

If query is a string storing an SQL statement. Write statements so that the data is fetched based on query from SQL database Mydata.

Python Pandas

3 Likes

Answer

Let query store the following SQL statement:

query = "SELECT * FROM EMPLOYEE WHERE department = 'Human Resource'"
import pandas as pd
import mysql.connector as sqltor
mycon = sqltor.connect(host = "localhost",
                        user = "root", 
                        passwd = "MyPass", 
                        database = "Mydata")      
query = "SELECT * FROM EMPLOYEE WHERE department = 'Human Resource'"
mdf = pd.read_sql(query, mycon)
print(mdf)
mycon.close()

Answered By

1 Like


Related Questions