Skip to main contentSkip to solution

Arrange the following steps of reading Data from MySQL to Pandas in correct order.

A. import sqlalchemy

B. df = pd.read_sql_query('SELECT * FROM INVENTORY', engine)

C. pip install pymysql

D. pip install sqlalchemy

E. engine=create_engine('mysql+pymysql://root:smsmb@localhost:3306/CARSHOWROOM')

Solution

✅ Correct Option: 2

pip install pymysql: installs the driver that lets Python talk to MySQL.

pip install sqlalchemy: installs the library that creates the database connection.

import sqlalchemy: imports the installed library into the program.

engine=create_engine('mysql+pymysql://root:smsmb@localhost:3306/CARSHOWROOM'): creates the connection to the CARSHOWROOM database.

df = pd.read_sql_query('SELECT * FROM INVENTORY', engine): uses that connection to read the INVENTORY table into a DataFrame.

Installing must come before importing, and the engine must exist before the query uses it.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question