Last Updated on June 26, 2022 by shibatau
I. What shall we learn?
We will visualizing Japan CPI using Python and the FRED API. You can learn how to get the data and the script for visualization here:
Identify the Inflation Cause Using Python
You have to register for an Account and get an API Key to access FRED data.
II. The scripts
Here are the scripts for Google Colaboratory:
!pip install fredapifrom fredapi import Fred
from calendar import month
from fredapi import Fred
import dateutil.parser as dp
import matplotlib.pyplot as plt
import datetime
fred = Fred("YOUR_API_KEY")
start_date = dp.parse('2012-01-01')
ukraine_war = dp.parse('2022-02-24')
cpi_mom = fred.get_series('JPNCPIALLMINMEI')
cpi_mom = cpi_mom[cpi_mom.index > start_date]
plt.figure(figsize=(12,8))
plt.plot(cpi_mom)
plt.axvline(ukraine_war,c='red')
plt.text(ukraine_war+datetime.timedelta(days=-1500),102.8
,'Russia invaded Ukraine \n On 24 Feb 2022 -->'
,fontsize=20)
plt.text(ukraine_war+datetime.timedelta(days=-2400),100.8
,'Consumer Price Index \n started going up in Apr 2021 -->'
,fontsize=20)
plt.show()
