02 - Big - Mac - Inde (5) - JupyterLab
02 - Big - Mac - Inde (5) - JupyterLab
Reference:
Python requests function
json.dumps function
localhost:8888/lab/tree/02_Big_Mac_Index/Solved/Big_Mac_Index.ipynb 1/8
2/4/22, 9:09 PM Big_Mac_Index
import pandas as pd
import os
import json
import requests
from dotenv import load_dotenv
%matplotlib inline
True
Out[2]:
# Using the type funcion, confirm that the Quandl API key is
# available for use in the notebook
type(quandl_api_key)
str
Out[3]:
end_date
Big Mac index for. For this activity, you can set both dates
to 2020-07-31 .
In [4]:
# Create `start_date` and `end_date` variables
# Both should hold the same date of `2020-07-31`
start_date = '2020-07-31'
end_date = '2020-07-31'
Step 5:
notebookReview the
supplies. endpoint
You’ll useURLs
thesethat
URLsthe
tostarter
access the
endpoints for the Big Mac index from
United States, Canada, and Mexico. three countries: the
In [5]:
big_mac_usa = "https://www.quandl.com/api/v3/datasets/ECONOMIST/BIGMAC_USA?start
big_mac_can = "https://www.quandl.com/api/v3/datasets/ECONOMIST/BIGMAC_CAN?start
big_mac_mex = "https://www.quandl.com/api/v3/datasets/ECONOMIST/BIGMAC_MEX?start
{
"dataset": {
"collapse": null,
"column_index": null,
"column_names": [
"Date",
"local_price",
"dollar_ex",
localhost:8888/lab/tree/02_Big_Mac_Index/Solved/Big_Mac_Index.ipynb 3/8
2/4/22, 9:09 PM Big_Mac_Index
"dollar_price",
"dollar_ppp",
"dollar_valuation",
"dollar_adj_valuation",
"euro_adj_valuation",
"sterling_adj_valuation",
"yen_adj_valuation",
"yuan_adj_valuation"
],
"data": [
[
"2020-07-31",
5.71,
1.0,
5.71,
1.0,
0.0,
0.0,
-1.9,
12.2,
27.900000000000002,
7.000000000000001
]
],
"database_code": "ECONOMIST",
"database_id": 5330,
"dataset_code": "BIGMAC_USA",
"description": "The Big Mac Index is an informal measure of currency exchang
e rates at ppp. It measures their value against a similar basket of goods and se
rvices, in this case a Big Mac. Differing prices at market exchange rates would
imply that one currency is under or overvalued.",
"end_date": "2020-07-31",
"frequency": "daily",
"id": 9776656,
"limit": null,
"name": "Big Mac Index - United States",
"newest_available_date": "2020-07-31",
"oldest_available_date": "2000-04-30",
"order": null,
"premium": false,
"refreshed_at": "2020-11-15T00:00:29.042Z",
"start_date": "2020-07-31",
"transform": null,
"type": "Time Series"
}
}
In [7]:
# Make the API call for the CAN Big Mac Index information
# using requests.get
response_can = requests.get(big_mac_can).json()
{
"dataset": {
"collapse": null,
"column_index": null,
"column_names": [
localhost:8888/lab/tree/02_Big_Mac_Index/Solved/Big_Mac_Index.ipynb 4/8
2/4/22, 9:09 PM Big_Mac_Index
"Date",
"local_price",
"dollar_ex",
"dollar_price",
"dollar_ppp",
"dollar_valuation",
"dollar_adj_valuation",
"euro_adj_valuation",
"sterling_adj_valuation",
"yen_adj_valuation",
"yuan_adj_valuation"
],
"data": [
[
"2020-07-31",
6.88,
1.3552,
5.0767414403778,
1.2049036777583177,
-11.09,
2.3,
0.3,
14.7,
30.8,
9.4
]
],
"database_code": "ECONOMIST",
"database_id": 5330,
"dataset_code": "BIGMAC_CAN",
"description": "The Big Mac Index is an informal measure of currency exchang
e rates at ppp. It measures their value against a similar basket of goods and se
rvices, in this case a Big Mac. Differing prices at market exchange rates would
imply that one currency is under or overvalued.",
"end_date": "2020-07-31",
"frequency": "daily",
"id": 9776618,
"limit": null,
"name": "Big Mac Index - Canada",
"newest_available_date": "2020-07-31",
"oldest_available_date": "2000-04-30",
"order": null,
"premium": false,
"refreshed_at": "2020-11-15T00:00:29.042Z",
"start_date": "2020-07-31",
"transform": null,
"type": "Time Series"
}
}
In [8]:
# Make the API call for the MEX Big Mac Index information
# using requests.get
response_mex = requests.get(big_mac_mex).json()
localhost:8888/lab/tree/02_Big_Mac_Index/Solved/Big_Mac_Index.ipynb 5/8
2/4/22, 9:09 PM Big_Mac_Index
"dataset": {
"collapse": null,
"column_index": null,
"column_names": [
"Date",
"local_price",
"dollar_ex",
"dollar_price",
"dollar_ppp",
"dollar_valuation",
"dollar_adj_valuation",
"euro_adj_valuation",
"sterling_adj_valuation",
"yen_adj_valuation",
"yuan_adj_valuation"
],
"data": [
[
"2020-07-31",
50.0,
22.436,
2.2285612408629,
8.75656742556918,
-60.971,
-33.0,
-34.300000000000004,
-24.8,
-14.2,
-28.299999999999997
]
],
"database_code": "ECONOMIST",
"database_id": 5330,
"dataset_code": "BIGMAC_MEX",
"description": "The Big Mac Index is an informal measure of currency exchang
e rates at ppp. It measures their value against a similar basket of goods and se
rvices, in this case a Big Mac. Differing prices at market exchange rates would
imply that one currency is under or overvalued.",
"end_date": "2020-07-31",
"frequency": "daily",
"id": 9776636,
"limit": null,
"name": "Big Mac Index - Mexico",
"newest_available_date": "2020-07-31",
"oldest_available_date": "2000-04-30",
"order": null,
"premium": false,
"refreshed_at": "2020-11-15T00:00:29.042Z",
"start_date": "2020-07-31",
"transform": null,
"type": "Time Series"
}
}
Step 7:
United Review
States. the output
Identify the from the Big
key-value Mac
pairs Index
that for
definethe
the
response object. Determine how to get the
localhost:8888/lab/tree/02_Big_Mac_Index/Solved/Big_Mac_Index.ipynb 6/8
and dollar_ppp data elements. Use
2/4/22, 9:09 PM Big_Mac_Index
dollar_price
this
theseinformation
indicators to create
for the a DataFrame
United States, with the
Canada, data
and of
Mexico.
In [9]:
# Set the Big Mac Index data to create a DataFrame
big_mac_index_data = {
"dollar_price": [
response_usa["dataset"]["data"][0][3],
response_can["dataset"]["data"][0][3],
response_mex["dataset"]["data"][0][3]
],
"dollar_ppp": [
response_usa["dataset"]["data"][0][4],
response_can["dataset"]["data"][0][4],
response_mex["dataset"]["data"][0][4]
]
}
Step 8: Use the DataFrame to create a bar chart that compares the
dollar_price and the dollar_ppp of the United States,
Canada, and Mexico.
In [11]:
# Create a bar chart to analyze the Big Mac Index for the United States,
# Canada and Mexico
# Be sure to include a title and adjust the figure size.
big_mac_index_df.plot.bar(figsize=(10,7),
title="Big Mac Index - USA, Canada & Mexico")
localhost:8888/lab/tree/02_Big_Mac_Index/Solved/Big_Mac_Index.ipynb 7/8
2/4/22, 9:09 PM Big_Mac_Index
In [ ]:
localhost:8888/lab/tree/02_Big_Mac_Index/Solved/Big_Mac_Index.ipynb 8/8