Consumer price indice

Tags: #fao #opendata #food #analytics #plotly
Author: Dereck DANIEL
Last update: 2023-04-12 (Created: 2021-06-10)
Description: This notebook provides an analysis of the changes in consumer prices over time as measured by the Food and Agriculture Organization's Consumer Price Index.


Import librairies

import requests, zipfile, io
import matplotlib.pyplot as plt
import naas_drivers
import pandas as pd
import as px
import csv
import codecs
import plotly.graph_objects as go

Set the variables

filename = "ConsumerPriceIndices_E_All_Data_(Normalized).csv"
zip_file_url = ""

Get the data

r = requests.get(zip_file_url, stream=True)
z = zipfile.ZipFile(io.BytesIO(r.content))
df = pd.read_csv(filename, encoding="latin-1")
df.to_csv(filename, index=False)
df = pd.read_csv(filename)


Sort the data

df = df[df["Item Code"] == 23013]
df = df[df.Year == 2020]
dfmax10 = (
df.groupby(["Area", "Year"])
.sort_values("Value", ascending=False)
dfmin10 = (
df.groupby(["Area", "Year"])
.sort_values("Value", ascending=True)


Display the plot of the Top 10 of the biggest evolution in 2020

dfmax10y = dfmax10["Area"].head(10).iloc[::-1]
dfmax10x = dfmax10["Value"].head(10).iloc[::-1]
fig = go.Figure(go.Bar(x=dfmax10x, y=dfmax10y, orientation="h"))
fig.update_layout(title_text="Top 10 of the biggest evolution in 2020")

Display the plot of the Top 10 of the worst evolution in 2020

dfmin10y = dfmin10["Area"].head(10).iloc[::-1]
dfmin10x = dfmin10["Value"].head(10).iloc[::-1]
fig = go.Figure(go.Bar(x=dfmin10x, y=dfmin10y, orientation="h"))
fig.update_layout(title_text="Top 10 of the worst evolution in 2020")
Last modified 1mo ago