Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the pandas library.
Data Analysis Python
import [1] as pd
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'numpy' instead of 'pandas' for data frames.
Importing 'sqlite3' when pandas is needed.
✗ Incorrect
We use import pandas as pd to work with data tables easily.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
We use sqlite3.connect() to open a connection to the database file.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The SQL query must be a string, so it needs quotes around it.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the database filename instead of the connection object.
Not quoting the table name string.
✗ Incorrect
We pass the table name as a string and the connection object to read the table.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Engine' instead of 'create_engine' for import or engine creation.
Passing the query without quotes.
✗ Incorrect
We import create_engine, use it to make an engine, then pass a SQL query string to pd.read_sql.