Skip to main contentSkip to solution

Which function is used to read a sql query into a dataFrame?

Solution

✅ Correct Option: 2

pandas.read_sql_query() runs a SQL query through a database connection and returns the result as a DataFrame. It takes the query string and a connection (such as a SQLAlchemy engine or an sqlite3 connection) as arguments.


Options 1 and 3: the underscores are missing from the names, so these functions do not exist in pandas.

Option 4: read_query() is not a pandas function; the real name is read_sql_query().

Pandas also has read_sql() (with an underscore), which accepts either a query or a table name, and read_sql_table(), which reads a whole table.

Keyboard Shortcuts

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