The Landscape of the Major Food Staples in Ghana

The dataset used in this project is a CSV file of the Global Food Prices Database by WFP - World Food Programme.


In [6]:
# Open the file and read its content.
raw_data = open('WFPVAM_FoodPrices_24-01-2017.csv', 'r').read()

In [7]:
# Split the raw_data on every newline.
raw_data = raw_data.split('\n')
# Take of the headers
raw_data_no_header = raw_data[1:]

In [8]:
# Make a list of lists of the raw_data_no_header
staples_data = []
for food_info in raw_data_no_header:
    info = food_info.split(',')
    staples_data.append(info)

In [9]:
def load_data_by_country(country):
    """Fetch data based on a specific country"""
    country_data = []
    for info in staples_data:
        if country in info:
            country_data.append(info)
    return(country_data)

In [10]:
# Fetch all data on Ghana
ghana_food_stapes = load_data_by_country(country="Ghana")

In [11]:
# Regions where there are market activities
regions = []
for info in ghana_food_stapes:
    current_region = info[3]
    if current_region not in regions:
        regions.append(current_region)

The regions where there are market activities - alphabetical order:


In [13]:
for region in sorted(regions):
    print("{} Region".format(region))


Ashanti Region
Brong Ahafo Region
Central Region
Eastern Region
Greater Accra Region
Northern Region
Upper East Region
Upper West Region
Volta Region
Western Region

In [16]:
# Market locations across the country
markets = []
for info in ghana_food_stapes:
    current_market = info[5]
    if current_market not in markets:
        markets.append(current_market)

In [20]:
# Markets per Regions
markets_in_regions = {}
for region in regions:
    current_market = []
    for market in markets:
        for info in ghana_food_stapes:
            if region == info[3] and market == info[5]:
                if market not in current_market:
                    current_market.append(market)
                markets_in_regions.update({region: current_market})

List of market locations per region


In [24]:
# Loop through the markets_in_regions dictionary
for region, markets in sorted(markets_in_regions.items()):
    print("\n{} REGION".format(region.upper()))
    if len(markets) > 1:
        # If market more than 1 make location plural
        print(" {} Market Locations:".format(len(markets)))
    elif len(markets) == 1:
        # If only 1 market, make location singular
        print(" {} Market Location:".format(len(markets)))
    for market in sorted(markets):
        print("\t{}".format(market))


ASHANTI REGION
 3 Market Locations:
	Ejura
	Kumasi
	Obuasi

BRONG AHAFO REGION
 2 Market Locations:
	Sunyani
	Techiman

CENTRAL REGION
 2 Market Locations:
	Cape Coast
	Mankessim

EASTERN REGION
 1 Market Location:
	Koforidua

GREATER ACCRA REGION
 2 Market Locations:
	Accra
	Tema

NORTHERN REGION
 1 Market Location:
	Tamale

UPPER EAST REGION
 1 Market Location:
	Bolga

UPPER WEST REGION
 1 Market Location:
	Wa

VOLTA REGION
 1 Market Location:
	Ho

WESTERN REGION
 1 Market Location:
	Sekondi/Takoradi

The main staples in Ghana


In [26]:
staples = []
for info in ghana_food_stapes:
    current_staple = info[7]
    if current_staple not in staples:
        staples.append(current_staple)

for staple in sorted(staples):
    print(staple)


Cassava
Maize
Plantains (apentu)
Rice (imported)
Rice (local)
Yam

In [ ]: