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()
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
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.
Related questions:
2025: 30 May Shift 2
2025: 3 June Shift 2
2026: 21 May Shift 1
2026: 13 May Shift 2
2026: 26 May Shift 1