DA0-002 practice question 8 of 25

[Data Acquisition and Preparation]A data analyst needs to join together a table data source and a web API data source using Python. Which of the…

Full set: 111 questions

[Data Acquisition and Preparation]

A data analyst needs to join together a table data source and a web API data source using Python. Which of the following is the best way to accomplish this task?

Answer options
A: Convert the data from the API and database to a varchar format and convert them to pandas DataFrames that are then merged together.
B: Convert the data from the API and database to a JSON format and convert them to pandas DataFrames that are then merged together. Correct answer
C: Convert the data from the API and database to a TXT format and convert them to pandas DataFrames that are then merged together.
D: Convert the data from the API and database to a string format and convert them to pandas DataFrames that are then merged together.
Correct Answer:
B. Convert the data from the API and database to a JSON format and convert them to pandas DataFrames that are then merged together.
Explanation

The most efficient and standard method for this task is to work with structured data formats that Python's data analysis libraries, like pandas, are optimized for. Web APIs commonly return data in JSON (JavaScript Object Notation) format. This structured format can be directly and easily parsed into a pandas DataFrame, preserving data types and relationships. Similarly, data queried from a database can be loaded directly into a DataFrame. Once both data sources are represented as DataFrames, pandas provides powerful and optimized merge or join functions to combine them based on common keys. This approach minimizes intermediate conversion steps and avoids the loss of data type information.

Why Incorrect

A. varchar is a database-specific data type, not a universal data interchange format. Converting all data to this string-like type would unnecessarily discard valuable numeric and date-type information.
C. Converting structured API and database data to a flat TXT file is an inefficient intermediate step that adds complexity and risks data integrity issues during parsing.
D. Converting all data to a generic string format is a poor practice as it loses essential data type information (e.g., integers, floats), making subsequent numerical analysis and joins difficult.

References

1. Pandas Official Documentation

IO Tools (JSON): The documentation explicitly details the pandas.readjson function for converting a JSON string directly into a pandas DataFrame. This is the standard method for handling API data.

Source: Pandas Development Team. (2023). pandas-docs: IO Tools (Text

CSV

HDF5

…). Section: JSON. Retrieved from https://pandas.pydata.org/pandas-docs/stable/userguide/io.html#json

2. Pandas Official Documentation

IO Tools (SQL): The documentation shows the pandas.readsql function

which is designed to read the result of a SQL query directly into a DataFrame

preserving data types from the database where possible.

Source: Pandas Development Team. (2023). pandas-docs: IO Tools (Text

CSV

HDF5

…). Section: SQL queries. Retrieved from https://pandas.pydata.org/pandas-docs/stable/userguide/io.html#sql-queries

3. University of Illinois Urbana-Champaign

Courseware: In the "Data Visualization" course materials

the standard workflow for handling web data is demonstrated. It involves making an API request

parsing the resulting JSON response

and loading it into a data structure like a pandas DataFrame for analysis.

Source: University of Illinois Urbana-Champaign. (2022). CS 307: Working with APIs and JSON. Week 3 Notes. Retrieved from https://uiuc-ischool-dataviz.github.io/spring2022/week03/workingwithapisandjson.html (Specifically

the section on parsing JSON and creating DataFrames).

Scroll to Top