0
0
Data Analysis Pythondata~10 mins

Reading from SQL databases in Data Analysis Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the pandas library.

Data Analysis Python
import [1] as pd
Drag options to blanks, or click blank then click option'
Asqlite3
Bpandas
Csqlalchemy
Dnumpy
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'numpy' instead of 'pandas' for data frames.
Importing 'sqlite3' when pandas is needed.
2fill in blank
medium

Complete the code to create a connection to a SQLite database file named 'data.db'.

Data Analysis Python
import sqlite3
conn = sqlite3.[1]('data.db')
Drag options to blanks, or click blank then click option'
Acreate
Bopen
Cstart
Dconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'open' instead of 'connect' causes an error.
Trying to use 'create' which is not a valid method here.
3fill in blank
hard

Fix the error in the code to read a SQL query into a pandas DataFrame.

Data Analysis Python
df = pd.read_sql_query([1], conn)
Drag options to blanks, or click blank then click option'
ASELECT * FROM table
B"SELECT * FROM table"
CSELECT * FROM table;
D'SELECT * FROM table'
Attempts:
3 left
💡 Hint
Common Mistakes
Writing the query without quotes causes a syntax error.
Adding a semicolon inside the string is optional but not required.
4fill in blank
hard

Fill both blanks to create a DataFrame from a SQL table named 'employees' using pandas.

Data Analysis Python
df = pd.read_sql_table([1], [2])
Drag options to blanks, or click blank then click option'
A'employees'
Bconn
C'data.db'
Dsqlite3
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the database filename instead of the connection object.
Not quoting the table name string.
5fill in blank
hard

Fill all three blanks to read data from a SQL database using SQLAlchemy engine and pandas.

Data Analysis Python
from sqlalchemy import [1]
engine = [2]('sqlite:///data.db')
df = pd.read_sql([3], engine)
Drag options to blanks, or click blank then click option'
Acreate_engine
B'SELECT * FROM users'
DEngine
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Engine' instead of 'create_engine' for import or engine creation.
Passing the query without quotes.