0% found this document useful (0 votes)
3 views

Practice assignment 2

This assignment focuses on working with JSON data from a CoinGecko API to analyze Bitcoin market data. It involves extracting relevant data into a list of dictionaries, transforming it into a Pandas DataFrame, and performing basic data analysis. The final output includes saving the processed data as both a CSV and an HTML file.

Uploaded by

jcstrow100
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Practice assignment 2

This assignment focuses on working with JSON data from a CoinGecko API to analyze Bitcoin market data. It involves extracting relevant data into a list of dictionaries, transforming it into a Pandas DataFrame, and performing basic data analysis. The final output includes saving the processed data as both a CSV and an HTML file.

Uploaded by

jcstrow100
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Module 1 – Practice assignment 2

Working with JSON Data and Pandas

Objective: In this assignment, you will practice working with JSON data from a free API, from
https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=7
extracting data into a list of dictionaries, converting JSON data to a Pandas DataFrame using
json_normalize, and using Python functions like enumerate

1. API Request and JSON Data

 Print the top-level keys of the JSON response to understand its structure (use
data.keys() )

Investigate the structure of the JSON response in an online JSON viewer like
https://jsonviewer.stack.hu/ . You will need to know how it looks like in order to be able to
process this data. You can open the API link in a browser to get the ‘raw’ data as well (may be
easier to copy-past from the browser compared to the Jupyter notebook cell).

Note that ‘prices’ holds a list: a timestamp, and the price

2. List of Dictionaries

When you are looping through a list, it may be helpful to use enumerate. Enumerate will give
you a tuple, of each list element as well as a counter.

 Extract the prices, market_caps, and total_volumes data from the JSON response (each
of these will be a list).
 Create a list of dictionaries where each dictionary represents a data point and contains:
Timestamp
Price
Market Cap
Volume
 Add a unique identifier (ID) to each dictionary (0, 1, 2, …)

3. Data Transformation

 Add a column Daily Change to calculate the difference in prices compared to the
previous day.
Initialize the first data point's daily change as 0 and use a for loop to calculate the daily
change for subsequent data points.
 Add a column Daily Percentage Change to calculate the percentage change in price:
Daily Percentage Change = ((Current Price - Previous Price) / Previous Price) * 100
4. JSON to Pandas DataFrame
 Convert the list of dictionaries to a Pandas DataFrame.
 Display the first 5 rows of the DataFrame to verify the data structure.

5. Data Analysis and Display

 Display minimum, average and maximum values for Price, Daily Change and Daily
Percentage Change.
 Identify the dates with the highest and lowest prices; for example
df["price"].max() will give the highest price, and df["price"].idxmax()
will give the index of the observation with the highest price

6. Export

Save the processed DataFrame as:

 A CSV file named bitcoin_analysis.csv.


 An HTML file named bitcoin_analysis.html.

You might also like