Skip to content

Instantly share code, notes, and snippets.

@fela
Created March 30, 2023 20:06
Show Gist options
  • Save fela/efc20b7b4ecf98084508a71e4c0929dd to your computer and use it in GitHub Desktop.
Save fela/efc20b7b4ecf98084508a71e4c0929dd to your computer and use it in GitHub Desktop.
GPT Analisis of file
# Assistant:
{"comment": "Printing first few lines of the file", "python": "with open('food-enforcement.json') as f:\n for i in range(3):\n print(f.readline().strip())"}
## Extracting comment:
Printing first few lines of the file
## Extracting python code:
with open('food-enforcement.json') as f:
for i in range(3):
print(f.readline().strip())
## Do you want to execute this code? (y/n)
y
# User:
output:
[
{
"status": "Terminated",
# Assistant:
{"comment": "Reading the json file into a variable", "python": "import json\n\nwith open('food-enforcement.json', 'r') as f:\n data = json.load(f)"}
## Extracting comment:
Reading the json file into a variable
## Extracting python code:
import json
with open('food-enforcement.json', 'r') as f:
data = json.load(f)
## Do you want to execute this code? (y/n)
y
# User:
# Assistant:
{"comment": "Printing the keys of the first item in the data list", "python": "print(list(data[0].keys()))"}
## Extracting comment:
Printing the keys of the first item in the data list
## Extracting python code:
print(list(data[0].keys()))
## Do you want to execute this code? (y/n)
y
# User:
output:
['status', 'city', 'state', 'country', 'classification', 'openfda', 'product_type', 'event_id', 'recalling_firm', 'address_1', 'address_2', 'postal_code', 'voluntary_mandated', 'initial_firm_notification', 'distribution_pattern', 'recall_number', 'product_description', 'product_quantity', 'reason_for_recall', 'recall_initiation_date', 'center_classification_date', 'termination_date', 'report_date', 'code_info', 'more_code_info']
# Assistant:
{"comment": "Counting items in the dataset where status is 'Terminated'", "python": "terminated_count = len([item for item in data if item['status'] == 'Terminated'])\nprint(terminated_count)"}
## Extracting comment:
Counting items in the dataset where status is 'Terminated'
## Extracting python code:
terminated_count = len([item for item in data if item['status'] == 'Terminated'])
print(terminated_count)
## Do you want to execute this code? (y/n)
y
# User:
output:
22041
# Assistant:
{"comment": "Counting the number of unique product types in the dataset", "python": "unique_product_types = set([item['product_type'] for item in data])\nprint(len(unique_product_types))"}
## Extracting comment:
Counting the number of unique product types in the dataset
## Extracting python code:
unique_product_types = set([item['product_type'] for item in data])
print(len(unique_product_types))
## Do you want to execute this code? (y/n)
y
# User:
output:
1
# Assistant:
{"comment": "Checking the unique product type present in the dataset", "python": "print(unique_product_types)"}
## Extracting comment:
Checking the unique product type present in the dataset
## Extracting python code:
print(unique_product_types)
## Do you want to execute this code? (y/n)
y
# User:
output:
{'Food'}
# Assistant:
{"comment": "Counting items in the dataset where voluntary_mandated is 'Voluntary: Firm Initiated'", "python": "voluntary_count = len([item for item in data if item['voluntary_mandated'] == 'Voluntary: Firm Initiated'])\nprint(voluntary_count)"}
## Extracting comment:
Counting items in the dataset where voluntary_mandated is 'Voluntary: Firm Initiated'
## Extracting python code:
voluntary_count = len([item for item in data if item['voluntary_mandated'] == 'Voluntary: Firm Initiated'])
print(voluntary_count)
## Do you want to execute this code? (y/n)
y
# User:
output:
929
# Assistant:
{"comment": "Calculating the percentage of voluntary recalls out of terminated recalls", "python": "percentage = (voluntary_count / terminated_count) * 100\nprint(percentage)"}
## Extracting comment:
Calculating the percentage of voluntary recalls out of terminated recalls
## Extracting python code:
percentage = (voluntary_count / terminated_count) * 100
print(percentage)
## Do you want to execute this code? (y/n)
y
# User:
output:
4.2148722834717125
# Assistant:
{"comment": "In this dataset, approximately 4.21% of the total terminated food recalls were initiated voluntarily by the firm. This indicates that only a small proportion of recalls were proactive measures taken by the firms.", "python": ""}
## Extracting comment:
In this dataset, approximately 4.21% of the total terminated food recalls were initiated voluntarily by the firm. This indicates that only a small proportion of recalls were proactive measures taken by the firms.
## Extracting python code:
## Do you want to execute this code? (y/n)
y
# User:
# Assistant:
{"comment": "Moving on to analyze the reason for recall, let's find out the top 5 most common reasons.", "python": "from collections import Counter\n\nreasons = [item['reason_for_recall'] for item in data]\ncounts = Counter(reasons)\ncommon_reasons = counts.most_common(5)\nprint(common_reasons)"}
## Extracting comment:
Moving on to analyze the reason for recall, let's find out the top 5 most common reasons.
## Extracting python code:
from collections import Counter
reasons = [item['reason_for_recall'] for item in data]
counts = Counter(reasons)
common_reasons = counts.most_common(5)
print(common_reasons)
## Do you want to execute this code? (y/n)
y
# User:
output:
[('Product may contain undeclared milk.', 618), ("Products not manufactured under GMP's", 353), ('Products were not held at an appropriate temperature due to a mechanical malfunction during transportation.', 330), ('Five patients who were treated in a single hospital in Kansas were infected with one of four rare strains of Listeria monocytogenes.', 286), ('Product may be contaminated with Listeria monocytogenes.', 281)]
# Assistant:
{"comment": "The top 5 most common reasons for food recalls in this dataset are: 1. Undeclared milk presence, 2. Products not manufactured under Good Manufacturing Practices, 3. Inappropriate storage temperature during transportation, 4. Infection caused by Listeria monocytogenes in a hospital in Kansas, and 5. Possible contamination with Listeria monocytogenes. Let's explore the distribution of voluntary and mandated recalls among these reasons.", "python": ""}
## Extracting comment:
The top 5 most common reasons for food recalls in this dataset are: 1. Undeclared milk presence, 2. Products not manufactured under Good Manufacturing Practices, 3. Inappropriate storage temperature during transportation, 4. Infection caused by Listeria monocytogenes in a hospital in Kansas, and 5. Possible contamination with Listeria monocytogenes. Let's explore the distribution of voluntary and mandated recalls among these reasons.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment