Consumer price indice
Tags: #fao #opendata #food #analytics
Author: Dereck DANIEL
Food Balance Sheet presents a comprehensive picture of the pattern of a country's food supply during a specified reference period. The food balance sheet shows for each food item - i.e. each primary commodity and a number of processed commodities potentially available for human consumption - the sources of supply and its utilization. The total quantity of foodstuffs produced in a country added to the total quantity imported and adjusted to any change in stocks that may have occurred since the beginning of the reference period gives the supply available during that period. On the utilization side a distinction is made between the quantities exported, fed to livestock, used for seed, put to manufacture for food use and non-food uses, losses during storage and transportation, and food supplies available for human consumption. The per caput supply of each such food item available for human consumption is then obtained by dividing the respective quantity by the related data on the population actually partaking of it. Data on per caput food supplies are expressed in terms of quantity and - by applying appropriate food composition factors for all primary and processed products - also in terms of caloric value and protein and fat content. Source: http://www.fao.org/faostat/en/?#data/FBS

Input

Import librairies

1
import requests, zipfile, io
2
import matplotlib.pyplot as plt
3
import naas_drivers
4
import pandas as pd
5
import plotly.express as px
6
import csv
7
import codecs
8
import plotly.graph_objects as go
Copied!

Set the variables

1
filename = "ConsumerPriceIndices_E_All_Data_(Normalized).csv"
2
zip_file_url = "http://fenixservices.fao.org/faostat/static/bulkdownloads/ConsumerPriceIndices_E_All_Data_(Normalized).zip"
Copied!

Get the data

1
r = requests.get(zip_file_url, stream=True)
2
z = zipfile.ZipFile(io.BytesIO(r.content))
3
z.extractall()
4
5
df = pd.read_csv(filename, encoding='latin-1')
6
df.to_csv(filename, index=False)
7
df = pd.read_csv(filename)
8
9
df.head()
Copied!

Model

Sort the data

1
df = df[df['Item Code'] == 23013]
2
df = df[df.Year == 2020]
3
dfmax10 = df.groupby(['Area', 'Year']).mean().reset_index().sort_values('Value', ascending=False).reset_index()
4
dfmin10 = df.groupby(['Area', 'Year']).mean().reset_index().sort_values('Value', ascending=True).reset_index()
Copied!

Output

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

1
dfmax10y = dfmax10['Area'].head(10).iloc[::-1]
2
dfmax10x = dfmax10['Value'].head(10).iloc[::-1]
3
4
fig = go.Figure(go.Bar(
5
x=dfmax10x,
6
y=dfmax10y,
7
orientation='h'))
8
9
fig.update_xaxes(type="log")
10
fig.update_layout(title_text='Top 10 of the biggest evolution in 2020')
11
12
fig.show()
Copied!

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

1
dfmin10y = dfmin10['Area'].head(10).iloc[::-1]
2
dfmin10x = dfmin10['Value'].head(10).iloc[::-1]
3
4
fig = go.Figure(go.Bar(
5
x=dfmin10x,
6
y=dfmin10y,
7
orientation='h'))
8
9
fig.update_layout(title_text='Top 10 of the worst evolution in 2020')
10
fig.show()
Copied!
Last modified 2mo ago
Copy link
Edit on GitHub