Economy: Visualizing Japan Consumer Price Index, fred api, python

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()

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.