Skip to content

Graded Quiz: Accessing databases using Python :Databases and SQL for Data Science with Python (IBM Data Analyst Professional Certificate) Answers 2025

1. Question 1

Correct command to connect Jupyter Notebook SQL extension to EMP.db:

  • %sql sqlite:///EMP.db

  • ❌ %sql

  • ❌ sqlite:///EMP.db

  • ❌ %sql sqlite:/EMP.db

  • ❌ %sql sqlite3://EMP.db

Explanation:

The correct URI format for SQLite is:

sqlite:///filename.db

2. Question 2

Select two uses of cell magic in Jupyter Notebooks:

  • Coding in a language other than Python

  • ❌ Converting notebook’s default language

  • Timing a complete cell block

  • ❌ Loading SQL database (done with SQL extension, not cell magic itself)

Explanation:

Examples:

  • %%bash, %%ruby, %%sql → run other languages

  • %%time, %%timeit → timing entire cell


3. Question 3

Outcome of:

conn = sqlite3.connect('HR.db')
data = pd.read_csv('./employees.csv')
data.to_sql('Employees', conn)
  • The CSV file is read and converted into an SQL table ‘Employees’ in HR.db

  • ❌ Converted to SQL file

  • ❌ Syntax error

  • ❌ CSV saved to HR.db file (incorrect phrasing)

Explanation:

to_sql() writes the dataframe into the SQLite database as a table.


4. Question 4

Correct ways to query a SQL table using Python (choose 2):

  • out = pandas.read_sql(query_statement, connection_object)

  • ❌ dataframe.read_sql

  • cursor = connection.execute(query_statement); out = cursor.fetchall()

  • ❌ out = connection.execute(query_statement)

Explanation:

Valid options are:

  • pandas.read_sql()

  • Using cursor + fetchall()


5. Question 5

Which command performs statistical analysis on dataframe df?

  • df.describe()

  • ❌ df.head()

  • ❌ df.tail()

  • ❌ df.info()

Explanation:

describe() gives count, mean, std, min, quartiles, max.


🧾 Summary Table

Q Correct Answer Key Concept
1 %sql sqlite:///EMP.db SQL extension connection
2 Run other languages, timing a cell Cell magic usage
3 CSV → SQL table in HR.db pandas.to_sql
4 read_sql & cursor.fetchall Querying DB with Python
5 df.describe() Statistical summary