Skip to main contentSkip to solution

After establishing the connection to fetch the data from the table of a database in SQL into a DataFrame, which of the following function will be used?

(A) pandas.read_sql_query()

(B) pandas.read_sql_table()

(C) pandas.read_sql_query_table()

(D) pandas.read_sql()

Solution

✅ Correct Option: 1

Pandas has three functions for loading SQL data into a DataFrame:

pandas.read_sql_query() runs a SQL query and returns the result as a DataFrame.

pandas.read_sql_table() reads a whole database table into a DataFrame, using an SQLAlchemy connection.

pandas.read_sql() is a wrapper that accepts either a SQL query or a table name and calls one of the two functions above.

So (A), (B) and (D) are valid.


Options 2, 3 and 4: pandas.read_sql_query_table() does not exist. It looks like a mix of the other two names.

Keyboard Shortcuts

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