Skip to main contentSkip to solution

Which of the following functions will read a SQL query into a DataFrame using the connection identifier 'sql_conn'?

Solution

✅ Correct Option: 1

pandas.read_sql_query(query, sql_conn) takes a SQL query string and a connection object, runs the query and returns the result as a DataFrame.


Option 2: read_sql_table reads a whole table by its name, not a query, and it needs a SQLAlchemy connection.

Option 3: this is a shell command that installs the PyMySQL driver. It is not a pandas function and reads no data.

Option 4: to_sql goes the other way. It writes a DataFrame into a SQL table and does not take a query.

Keyboard Shortcuts

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