Skip to content

This repository contains code and documentation for analyzing UK food hygiene ratings data. The analysis is divided into setting up the database, updating it with modifications, and conducting exploratory analysis using Python libraries like PyMongo and Pandas.

Notifications You must be signed in to change notification settings

SteveTuttle/uk-food-hygiene-analysis

Repository files navigation

uk-food-hygiene-analysis

UNC_data_bootcamp_module_12

Challenge Description

Background

The UK Food Standards Agency evaluates various establishments across the United Kingdom, and gives them a food hygiene rating. You've been contracted by the editors of a food magazine, Eat Safe, Love, to evaluate some of the ratings data in order to help their journalists and food critics decide where to focus future articles.

from the UNC Bootcamp instructions for this challenge

Deliverables

To complete this challenge I will be using MongoDB Compass and Jupyter Notebooks. This challenge is broken down into three parts, the details of each come from the BootCamp Instructions so there are no questions what I intend to accomplish. The three parts of this challenge are as follows:

  • Database and Jupyter Notebook Set Up
  • Update the Database
  • Exploratory Analysis

Part-1: Database and Jupyter Notebook Set Up

For this part of the challenge I will be using NoSQL_setup_starter.ipynb which I have renamed NoSQL_setup_sdt.ipynb going forward. To accomplish this part of the challenge of we must complete the following steps as per challenge instructions:

  1. Import the data provided in the establishments.json file from your Terminal. Name the database uk_food and the collection establishments. Copy the text you used to import your data from your Terminal to a markdown cell in your notebook.
  2. Within your notebook, import the libraries you need: PyMongo and Pretty Print.
  3. Create an instance of the Mongo Client.
  4. Confirm that you created the database and loaded the data properly:
  • List the databases you have in MongoDB. Confirm that uk_food is listed.
  • List the collection(s) in the database to ensure that establishments is there.
  • Find and display one document in the establishments collection using find_one and display with pprint.
  1. Assign the establishments collection to a variable to prepare the collection for use.

Part-2: Update the Database

The magazine editors have some requested modifications for the database before you can perform any queries or analysis for them.

from the UNC Bootcamp instructions for this challenge

For this part of the challenge I will continue to use NoSQL_setup_sdt.ipynb and make the following changes to the establishments collection per challenge instructions to complete the challenge:

  1. Add the following information to the database:
{
    "BusinessName":"Penang Flavours",
    "BusinessType":"Restaurant/Cafe/Canteen",
    "BusinessTypeID":"",
    "AddressLine1":"Penang Flavours",
    "AddressLine2":"146A Plumstead Rd",
    "AddressLine3":"London",
    "AddressLine4":"",
    "PostCode":"SE18 7DY",
    "Phone":"",
    "LocalAuthorityCode":"511",
    "LocalAuthorityName":"Greenwich",
    "LocalAuthorityWebSite":"http://www.royalgreenwich.gov.uk",
    "LocalAuthorityEmailAddress":"[email protected]",
    "scores":{
        "Hygiene":"",
        "Structural":"",
        "ConfidenceInManagement":""
    },
    "SchemeType":"FHRS",
    "geocode":{
        "longitude":"0.08384000",
        "latitude":"51.49014200"
    },
    "RightToReply":"",
    "Distance":4623.9723280747176,
    "NewRatingPending":True
}
  1. Find the BusinessTypeID for "Restaurant/Cafe/Canteen" and return only the BusinessTypeID and BusinessType fields.
  2. Update the new restaurant with the BusinessTypeID you found.
  3. The magazine is not interested in any establishments in Dover, so check how many documents contain the Dover Local Authority. Then, remove any establishments within the Dover Local Authority from the database, and check the number of documents to ensure they were deleted.
  4. Some of the number values are stored as strings, when they should be stored as numbers.
  • Use update_many to convert latitude and longitude to decimal numbers.
  • Use update_many to convert RatingValue to integer numbers.

Part-3: Exploratory Analysis

Eat Safe, Love has specific questions they want you to answer, which will help them find the locations they wish to visit and avoid.

from the UNC Bootcamp instructions for this challenge

For the final part of the Challenge I will open NoSQL_analysis_starter.ipynb and rename it NoSQL_analysis_sdt.ipynb, then I will follow the instructions and notes from the Challenge that I need to be aware of throughout the dataset listed below:

  • RatingValue refers to the overall rating decided by the Food Authority and ranges from 1-5. The higher the value, the better the rating.
  • Note: This field also includes non-numeric values such as 'Pass', where 'Pass' means that the establishment passed their inspection but isn't given a number rating. We will coerce non-numeric values to nulls during the database setup before converting ratings to integers.
  • The scores for Hygiene, Structural, and ConfidenceInManagement work in reverse. This means, the higher the value, the worse the establishment is in these areas.

Use the following questions to explore the database, and find the answers, so you can provide them to the magazine editors.

Unless otherwise stated, for each question:

  • Use count_documents to display the number of documents contained in the result.
  • Display the first document in the results using pprint.
  • Convert the result to a Pandas DataFrame, print the number of rows in the DataFrame, and display the first 10 rows.
  1. Which establishments have a hygiene score equal to 20?

  2. Which establishments in London have a RatingValue greater than or equal to 4?

Hint: The London Local Authority has a longer name than "London" so you will need to use $regex as part of your search.

  1. What are the top 5 establishments with a RatingValue of 5, sorted by lowest hygiene score, nearest to the new restaurant added, "Penang Flavours"?

Hint: You will need to compare the geocode to find the nearest locations. Search within 0.01 degree on either side of the latitude and longitude.

  1. How many establishments in each Local Authority area have a hygiene score of 0? Sort the results from highest to lowest, and print out the top ten local authority areas.

Hint: You will need to use the aggregation method to answer this.

Resources

Bootcamp References

Module 12 Instructions   starter_code

  • NoSQL_analysis_starter.ipynb
  • NoSQL_setup_starter.ipynb

Resources

  • establishments.json   Special Thanks:
  • Jamie Miller
  • Mounika Mamindla
  • Lisa Shemanciik  

External References

(where possible will provide link to website)

About

This repository contains code and documentation for analyzing UK food hygiene ratings data. The analysis is divided into setting up the database, updating it with modifications, and conducting exploratory analysis using Python libraries like PyMongo and Pandas.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published