<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Yelp Dataset Challenge
Timothy Helton
Yelp is a website that allows patrons to review restaurants they have been to. The company runs a regular challenge to see if anyone can derive additional insights from the raw user reviews.
More information about the challenge may be found
here.
For excerises 1-4, use the Yelp business json file. For exercises 5-6, use the Yelp review json file.
<br>
<font color="red">
    NOTE
Step1:  Load Data
Create Instance of Yelp Class
Step2:  Exercise 1
Step3:  Exercise 2
Step4:  Exercise 3
Step5:  Exercise 4
Step6:  Exercise 5
Step7:  Exercise 6
<ASSISTANT_TASK:>
Python Code:
from k2datascience import yelp
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
%matplotlib inline
Explanation: Yelp Dataset Challenge
Timothy Helton
Yelp is a website that allows patrons to review restaurants they have been to. The company runs a regular challenge to see if anyone can derive additional insights from the raw user reviews.
More information about the challenge may be found
here.
For excerises 1-4, use the Yelp business json file. For exercises 5-6, use the Yelp review json file.
<br>
<font color="red">
    NOTE:
    <br>
    This notebook uses code found in the
    <a href="https://github.com/TimothyHelton/k2datascience/blob/master/k2datascience/yelp.py">
    <strong>k2datascience.yelp</strong></a> module.
    To execute all the cells do one of the following items:
    <ul>
        <li>Install the k2datascience package to the active Python interpreter.</li>
        <li>Add k2datascience/k2datascience to the PYTHON_PATH system variable.</li>
        <li>Create a link to the yelp.py file in the same directory as this notebook.</li>
</font>
Imports
End of explanation
ydc = yelp.YDC()
ydc.load_data()
business = ydc.file_data['business']
business.shape
business.head()
business.tail()
Explanation: Load Data
Create Instance of Yelp Class
End of explanation
ydc.get_zip_codes()
business.head()
Explanation: Exercise 1: Create a new column that contains only the zipcode.
End of explanation
ydc.get_restaurant_type()
business.head()
business.restaurant_type.ix[0]
Explanation: Exercise 2: The table contains a column called 'categories' and each entry in this column is populated by a list. We are interested in those businesses that are restaurants. Create a new column 'Restaurant_type' that contains a description of the restaurant based on the other elements of 'categories.
That is, if we have '[Sushi Bars, Japanese, Restaurants]' in categories the 'Restaurant_type will be '{'SushiBars': 1, 'Japanese': 1, 'Mexican': 0, ...}'
End of explanation
business.attributes = yelp.convert_boolean(business.attributes)
business.head()
business.attributes.ix[0]
Explanation: Exercise 3: Lets clean the 'attributes' column. The entries in this column are dictionaries. We need to do two things:
1) Turn all the True or False in the dictionary to 1s and 0s.
2) There are some entries within dictionaries that are dictionaries themselves, lets turn the whole entry into just one dictionary, for example if we have
'{'Accepts Credit Cards': True, 'Alcohol': 'none','Ambience': {'casual': False,'classy': False}}'
then turn it into
'{'Accepts Credit Cards':1, 'Alcohol_none': 1, 'Ambience_casual': 0, 'Ambience_classy': 0}'.
There might be other entries like {'Price Range': 1} where the values are numerical so we might want to change that into {'Price_Range_1': 1}.
The reason we modify categorical variables like this is that machine learning algorithms cannot interpret textual data like "True" and "False". They need numerical inputs such as 1 and 0.
End of explanation
ydc.calc_open_hours()
business.head(6)
Explanation: Exercise 4: Create a new column for every day of the week and fill it with the amount of hours the business is open that day.
Your approach should handle businesses that stay open late like bars and nightclubs.
End of explanation
review = ydc.file_data['review']
review.shape
review.head()
review.tail()
ydc.get_avg_stars()
ydc.file_data['business'].head()
Explanation: Exercise 5: Create a table with the average review for a business.
You will need to pull in a new json file and merge DataFrames for the next 2 exercises.
End of explanation
mask = ['name', 'restaurant_type', 'Friday', 'Saturday',
        'attributes', 'zip_code', 'stars_avg']
ydc.file_data['business'].loc[:, mask]
Explanation: Exercise 6: Create a new table that only contains restaurants with the following schema:
Business_Name | Restaurant_type | Friday hours | Saturday hours | Attributes | Zipcode | Average Rating
End of explanation
<END_TASK>