Which of the following functions will read a SQL query into a DataFrame using the connection identifier 'sql_conn'?
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.
Related questions:
2025: 22 May Shift 1
2025: 14 May Shift 1
2026: 29 May Shift 1
2026: 23 May Shift 2