<jupyter_start><jupyter_text>Food Inspections Evaluation  Problem Statment:<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.graph_objs as go
# ! conda install plotly<jupyter_output><empty_output><jupyter_text>Executive Summary  Datasets Description:  Data Import :<jupyter_code># Read in datasets from csv to pandas dataframes,
#load only useful columns
food_inspect_data = pd.read_csv('Data/Food_Inspections.csv')
# Quickly lowercase and camelcase all column names in a DataFrame
# we need to rename columns to use it with SQL later
food_inspect_data = food_inspect_data.rename(columns=lambda x: x.lower().replace(' ', '_').replace('#','').replace('-','_'))<jupyter_output><empty_output><jupyter_text>Display Data:<jupyter_code>food_inspect_data.head()
food_inspect_data.rename(columns={"license_": "license"}, inplace=True)<jupyter_output><empty_output><jupyter_text>Briefly describe the data:   B  Investigate the Dataset<jupyter_code>#check the shape of our dataset
food_inspect_data.shape
# information about dataset
food_inspect_data.info()
# total of missing values in each columns
# Verifying missing data
food_inspect_data.isnull().sum()
food_inspect_data.describe()
food_inspect_data.facility_type.value_counts()<jupyter_output><empty_output><jupyter_text>Preprocessing and Data Structure  Take just we need from dataset :<jupyter_code># Extracting facility_type Restaurant
# Only consider restaurants
food_inspect_data_restaurant = food_inspect_data[food_inspect_data['facility_type'] =='Restaurant']
food_inspect_data_restaurant.shape
food_inspect_data_restaurant.facility_type.count()
food_inspect_data_restaurant.head()
# Extracting inspection_type Canvass
# Only consider canvass inspections (not complaints or re-inspections)
food_inspect_data_restaurant = food_inspect_data_restaurant[food_inspect_data['inspection_type'] =='Canvass']
# Drop unnecessary columns Because we know we're working on a restaurant in Chicago 
food_inspect_data_restaurant = food_inspect_data_restaurant.drop(['facility_type', 'city', 'state','aka_name','inspection_type'], axis=1)
food_inspect_data_restaurant.isnull().sum()
# convert date type from str to datetime to easy apply date things
food_inspect_data_restaurant['inspection_date'] =  pd.to_datetime(food_inspect_data['inspection_date'])
food_inspect_data_restaurant.info()
# select date starting from 2013
food_inspect_data_restaurant = food_inspect_data_restaurant.loc[food_inspect_data_restaurant['inspection_date'] >= '2013']
food_inspect_data_restaurant.inspection_date.value_counts()
# to identify the result and we will take just successful bussniss
food_inspect_data_restaurant.loc[food_inspect_data_restaurant.violations.isna(), 'results'].value_counts()
# Only consider successful inspections
food_inspect_data_restaurant = food_inspect_data_restaurant[~food_inspect_data_restaurant.results.isin(["Out of Business", "Business Not Located", "No Entry"])]
food_inspect_data_restaurant.results.value_counts()<jupyter_output><empty_output><jupyter_text>Handeling Missing Value:<jupyter_code># df = df[df.latuidad.notna()]
# Drop duplicates
# food_inspect_data_restaurant.drop_duplicates("inspection_id", inplace=True)
## Drop "0" licenses
food_inspect_data_restaurant = food_inspect_data_restaurant[food_inspect_data_restaurant.license != 0]
food_inspect_data_restaurant.results.value_counts()
null_columns=food_inspect_data_restaurant.columns[food_inspect_data_restaurant.isnull().any()]
food_inspect_data_restaurant[null_columns].isnull().sum()
# filling the vailatuins 
food_inspect_data_restaurant.violations.fillna("No Violations", inplace = True)
#Drop rows with missing data
food_inspect_data_restaurant.dropna(subset=['latitude','zip','historical_wards_2003_2015','census_tracts'],inplace=True)
food_inspect_data_restaurant.info()
food_inspect_data_restaurant.isnull().sum()
# df = food_inspect_data_restaurant[food_inspect_data_restaurant.latitude.notna()]
# df[df.isnull().any(axis=1)][null_columns].head()
# df = df.dropna(axis=0, subset=['zip'])
# print(df[df["zip"].isnull()][null_columns])
# food_inspect_data_restaurant.violations.isnull().sum()
# df.info()
# df.isnull().sum()
# df.info()
# df.community_areas.head()
# df.wards.head()
# df.zip.dropna(inplace = True)<jupyter_output><empty_output><jupyter_text>Duplicated value<jupyter_code>sum(food_inspect_data_restaurant.duplicated())
# food_inspect_data_restaurant.drop_duplicates("inspection_id", inplace=True)
# food_inspect_data_restaurant.drop_duplicates(inplace=True)
# food_inspect_data_restaurant.info()<jupyter_output><empty_output><jupyter_text>Verify the values of data<jupyter_code>food_inspect_data_restaurant.dba_name.value_counts()
food_inspect_data_restaurant.license.value_counts()
food_inspect_data_restaurant.columns
food_inspect_data_restaurant.risk.value_counts()
food_inspect_data_restaurant.address.value_counts()
food_inspect_data_restaurant.zip.value_counts()
food_inspect_data_restaurant.inspection_date.value_counts()
food_inspect_data_restaurant.results.value_counts()
print(food_inspect_data_restaurant.violations.value_counts())
food_inspect_data_restaurant.latitude.value_counts()
food_inspect_data_restaurant.longitude.value_counts()
food_inspect_data_restaurant.columns
food_inspect_data_restaurant.location.value_counts()
food_inspect_data_restaurant.historical_wards_2003_2015.value_counts()
food_inspect_data_restaurant.zip_codes.value_counts()
food_inspect_data_restaurant.community_areas.value_counts()
food_inspect_data_restaurant.census_tracts.value_counts()
food_inspect_data_restaurant.wards.value_counts()<jupyter_output><empty_output><jupyter_text>Save the data set<jupyter_code>food_inspect_data_restaurant.to_csv('Food Inspections for Restaurant.csv')
food_inspect_data_restaurant.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09880546075085324, 'fraction_numerical': 0.004948805460750853, 'mean_word_length': 11.417372881355933, 'pattern_counts': {'":': 1, '<': 37, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '615022', 'license': 'NCSA', 'n_tokens_mistral': 2100, 'n_tokens_neox': 1987, 'n_words': 293, 'path': '.ipynb_checkpoints/food_inspections_evaluation-checkpoint.ipynb', 'repo_name': 'AseelAlawadh/GA', 'size': '5860'}