Which function is used to read a sql query into a dataFrame?
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.
Related questions:
2025: 20 May Shift 1
2025: 20 May Shift 1
2025: 14 May Shift 1