You are on page 1of 9

Part 1: Yelp Dataset Profiling and Understanding

1. Profile the data by finding the total number of records for each of the tables
below:

i. Attribute table = 10000


ii. Business table = 10000
iii. Category table = 10000
iv. Checkin table = 10000
v. elite_years table = 10000
vi. friend table = 10000
vii. hours table = 10000
viii. photo table = 10000
ix. review table = 10000
x. tip table = 10000
xi. user table =1000

2. Find the total distinct records by either the foreign key or primary key for
each table. If two foreign keys are listed in the table, please specify which
foreign key.

i. Business = 10000 (primary key)


ii. Hours = 1562 (Business_id foreign key)
iii. Category = 2643 (Business_id foreign key)
iv. Attribute = 1115 (Business_id foreign key)
v. Review = 9581 (User_id foreign key)
vi. Checkin = 493 (business_id foreign key)
vii. Photo = 6493 (business_id forein key)
viii. Tip = 3979 (business_id foreign key)
ix. User = 10000 (id primary key)
x. Friend = 11 (user_id foreign key)
xi. Elite_years = 2780 (user_id foreign key)

Note: Primary Keys are denoted in the ER-Diagram with a yellow key icon.

3. Are there any columns with null values in the Users table? Indicate "yes," or
"no."

Answer: No

SQL code used to arrive at answer:


select *
from user
where id is null
or
name is null
or
review_count is null
or
yelping_since is null
or
useful is null
or
funny is null
or
cool is null
or
fans is null
or
average_stars is null
or
compliment_hot is null
or
compliment_more is null
or
compliment_profile is null
or
compliment_cute is null
or
compliment_list is null
or
compliment_note is null
or
compliment_plain is null
or
compliment_cool is null
or
compliment_funny is null
or
compliment_writer is null
or
compliment_photos is null;

4. For each table and column listed below, display the smallest (minimum), largest
(maximum), and average (mean) value for the following fields:

i. Table: Review, Column: Stars

min: 1 max: 5 avg: 3.7082

ii. Table: Business, Column: Stars

min:1.0 max:5.0 avg: 3.6549

iii. Table: Tip, Column: Likes

min: 0 max: 2 avg: 0.0144

iv. Table: Checkin, Column: Count

min: 1 max: 53 avg: 1.9414

v. Table: User, Column: Review_count

min:0 max:2000 avg: 24.2995


5. List the cities with the most reviews in descending order:

SQL code used to arrive at answer:


select sum(review_count) as Total_reviews
,city
from business
group by city
order by total_reviews desc;

Copy and Paste the Result Below:


+---------------+-----------------+
| Total_reviews | city |
+---------------+-----------------+
| 82854 | Las Vegas |
| 34503 | Phoenix |
| 24113 | Toronto |
| 20614 | Scottsdale |
| 12523 | Charlotte |
| 10871 | Henderson |
| 10504 | Tempe |
| 9798 | Pittsburgh |
| 9448 | Montréal |
| 8112 | Chandler |
| 6875 | Mesa |
| 6380 | Gilbert |
| 5593 | Cleveland |
| 5265 | Madison |
| 4406 | Glendale |
| 3814 | Mississauga |
| 2792 | Edinburgh |
| 2624 | Peoria |
| 2438 | North Las Vegas |
| 2352 | Markham |
| 2029 | Champaign |
| 1849 | Stuttgart |
| 1520 | Surprise |
| 1465 | Lakewood |
| 1155 | Goodyear |
+---------------+-----------------+
(Output limit exceeded, 25 of 362 total rows shown)

6. Find the distribution of star ratings to the business in the following cities:

i. Avon

SQL code used to arrive at answer:

SELECT stars AS star_rating, count(stars) AS count


FROM business
WHERE city='Avon'
GROUP BY stars;
Copy and Paste the Resulting Table Below (2 columns – star rating and
count):

+-------------+-------+
| star_rating | count |
+-------------+-------+
| 1.5 | 1 |
| 2.5 | 2 |
| 3.5 | 3 |
| 4.0 | 2 |
| 4.5 | 1 |
| 5.0 | 1 |
+-------------+-------+

ii. Beachwood

SQL code used to arrive at answer:

SELECT stars AS star_rating, count(stars) AS count


FROM business
WHERE city='Beachwood'
GROUP BY stars;

Copy and Paste the Resulting Table Below (2 columns – star rating and
count):

+-------------+-------+
| star_rating | count |
+-------------+-------+
| 2.0 | 1 |
| 2.5 | 1 |
| 3.0 | 2 |
| 3.5 | 2 |
| 4.0 | 1 |
| 4.5 | 2 |
| 5.0 | 5 |
+-------------+-------+

7. Find the top 3 users based on their total number of reviews:

SQL code used to arrive at answer:


select name, sum(review_count) as ReviewCount
from user
group by id
order by ReviewCount desc
limit 3;

Copy and Paste the Result Below:


+--------+-------------+
| name | ReviewCount |
+--------+-------------+
| Gerald | 2000 |
| Sara | 1629 |
| Yuri | 1339 |
+--------+-------------+
8. Does posing more reviews correlate with more fans?

YES! It is correlated. Users with more reviews have more fans.

Please explain your findings and interpretation of the results:

+----------+----------+----------------------+-----------------+
| Range | NumUsers | Average_review_count | average_numfans |
+----------+----------+----------------------+-----------------+
| 0-9 | 9690 | 15.0085655315 | 0.447265221878 |
| 10-99 | 294 | 283.326530612 | 25.5986394558 |
| 100-1000 | 16 | 891.5 | 189.75 |
+----------+----------+----------------------+-----------------+

Select Range,
Count(*) as NumUsers,
Avg(review_count) as Average_review_count,
Avg(fans) as average_numfans
From (Select case
when fans between 0 and 9 then '0-9'
When fans between 10 and 99 then '10-99'
Else '100-1000'
END as Range, review_count, fans
From User)
group by Range;

9. Are there more reviews with the word "love" or with the word "hate" in them?

Answer: Love

SQL code used to arrive at answer:

Select count(*) as TotalCount,


case
when lower(text) like '%love%' then 'love'
When lower(text) like '%hate%' then 'hate'
Else 'other'
END as reaction
From review
Group by reaction;

10. Find the top 10 users with the most fans:

SQL code used to arrive at answer:


Select name, fans
from user
order by fans desc
Limit 10;

Copy and Paste the Result Below:


+-----------+------+
| name | fans |
+-----------+------+
| Amy | 503 |
| Mimi | 497 |
| Harald | 311 |
| Gerald | 253 |
| Christine | 173 |
| Lisa | 159 |
| Cat | 133 |
| William | 126 |
| Fran | 124 |
| Lissa | 120 |
+-----------+------+

Part 2: Inferences and Analysis

1. Pick one city and category of your choice and group the businesses in that city
or category by their overall star rating. Compare the businesses with 2-3 stars to
the businesses with 4-5 stars and answer the following questions. Include your
code.

i. Do the two groups you chose to analyze have a different distribution of hours?

City - Phoenix, Category - Food

select
Case
When business.stars >=4.0 Then '4-5 stars'
when business.stars >=2.0 then '2-3 stars'
else 'less than 2 hours'
end as Star_Rating,
count(distinct business.id) as BUSINESSID,
Count(distinct hours) as OPENINGDAYS, --finding out openeing days
Count(distinct hours)/count(distinct business.id) as AverageOpeningDays
From ((business inner join hours on business.id=hours.business_id) Inner join
Category on business.id=category.business_id)
where business.city='Phoenix' and Category.category='Food'
group by star_rating;

+-------------+------------+-------------+--------------------+
| Star_Rating | BUSINESSID | OPENINGDAYS | AverageOpeningDays |
+-------------+------------+-------------+--------------------+
| 2-3 stars | 1 | 7 | 7 |
| 4-5 stars | 1 | 7 | 7 |
+-------------+------------+-------------+--------------------+

Conclusion- Distributions of hours is equal for both 2-3 star business and 4-5 star
business for the city phoenix and for the category food.

ii. Do the two groups you chose to analyze have a different number of reviews?

City - Phoenix, Category - Food

select
Case
When business.stars >=4.0 Then '4-5 stars'
when business.stars >=2.0 then '2-3 stars'
else 'less than 2 hours'
end as Star_Rating,
count(distinct business.id) as BUSINESSID,
Sum(Review_count) as TotalReviews,
(Sum(Review_count)/count(distinct business.id)) as AverageReviews
From (business Inner join Category on business.id=category.business_id)
where business.city='Phoenix' and Category.category='Food'
group by star_rating;
+-------------+------------+--------------+----------------+
| Star_Rating | BUSINESSID | TotalReviews | AverageReviews |
+-------------+------------+--------------+----------------+
| 2-3 stars | 2 | 66 | 33 |
| 4-5 stars | 2 | 435 | 217 |
+-------------+------------+--------------+----------------+
Conclusion- Yes, Average number of reviews for 4-5 star business are a little more
than double than 2-3 star business.

iii. Are you able to infer anything from the location data provided between these
two groups? Explain.

+-------------+----------------------------------------+-------------
+-----------------------------+---------+
| Star_Rating | name | postal_code | address
| city |
+-------------+----------------------------------------+-------------
+-----------------------------+---------+
| 4-5 stars | Bootleggers Modern American Smokehouse | 85028 | 3375 E Shea
Blvd | Phoenix |
| 2-3 stars | Safeway Food & Drug | 85053 | 3450 W Bell
Rd | Phoenix |
| 2-3 stars | Starbucks | 85048 | 4605 E
Chandler Blvd, Ste A | Phoenix |
| 4-5 stars | Water N Ice | 85029 | 4212 W
Cactus Rd, Ste 1114 | Phoenix |
+-------------+----------------------------------------+-------------
+-----------------------------+---------+

SQL code used for analysis:


select
Case
When business.stars >=4.0 Then '4-5 stars'
when business.stars >=2.0 then '2-3 stars'
else 'less than 2 stars'
end as Star_Rating,
business.name,
business.postal_code,
business.address,
business.city
From (business Inner join Category on business.id=category.business_id)
where business.city='Phoenix' and Category.category='Food'
group by business.name;

2. Group business based on the ones that are open and the ones that are closed.
What differences can you find between the ones that are still open and the ones
that are closed? List at least two differences and the SQL code you used to arrive
at your answer.

i. Difference 1: The number of business open are a lot more than business that are
closed, and are also open for more number of days
ii. Difference 2: Average stars and the number of reviews is also greater for open
businesses

select is_open, avg(stars) as AVG_stars,


count(distinct review_count) as Num_reviews,
count(distinct id) as num__business,
count(hours) as open_days
from business inner join hours on business.id=hours.business_id
group by is_open;
+---------+---------------+-------------+---------------+-----------+
| is_open | AVG_stars | Num_reviews | num__business | open_days |
+---------+---------------+-------------+---------------+-----------+
| 0 | 3.63709677419 | 15 | 19 | 124 |
| 1 | 3.81906300485 | 51 | 98 | 619 |
+---------+---------------+-------------+---------------+-----------+

3. For this last part of your analysis, you are going to choose the type of
analysis you want to conduct on the Yelp dataset and are going to prepare the data
for analysis.

Ideas for analysis include: Parsing out keywords and business attributes for
sentiment analysis, clustering businesses to find commonalities or anomalies
between them, predicting the overall star rating for a business, predicting the
number of fans a user will have, and so on. These are just a few examples to get
you started, so feel free to be creative and come up with your own problem you want
to solve. Provide answers, in-line, to all of the following:

i. Indicate the type of analysis you chose to do:

Which Category has the most businesses and is the most popular category. Also,
which category is the most successful among the category with more than 10
businesses

ii. Write 1-2 brief paragraphs on the type of data you will need for your analysis
and why you chose that data:
The category 'Resturants' has the greateast number of business and is also open the
maximum number of days and is the most popular category.

The most successful business is Food because it has the biggest number of reviews
and still the average star rating is considerably high.
'Local Services' and 'Health and Medical' have the greatest number of star ratings
but are open the least number of days and the average number of reviews is
considerably low as compared to other categories.

iii. Output of your finished dataset:


+------------------+--------------+-------------+-----------+-----------+
| Category | num_business | avg_reviews | open_days | avg_stars |
+------------------+--------------+-------------+-----------+-----------+
| Restaurants | 43 | 87.0 | 289 | 3.54 |
| Shopping | 20 | 36.56 | 128 | 3.86 |
| Food | 15 | 101.85 | 97 | 3.76 |
| Nightlife | 15 | 79.57 | 98 | 3.46 |
| Bars | 14 | 82.49 | 94 | 3.53 |
| Health & Medical | 12 | 13.15 | 66 | 4.3 |
| Local Services | 11 | 8.25 | 71 | 4.26 |
+------------------+--------------+-------------+-----------+-----------+

iv. Provide the SQL code you used to create your final dataset:

select category.category as Category,


count(distinct business.id) as num_business,
round(avg(review_count),2) as avg_reviews,
count(hours) as open_days,
round(avg(stars),2) as avg_stars
from
business inner join hours on business.id=hours.business_id
inner join category on category.business_id=business.id
group by category.category
having num_business>10
order by num_business desc;

You might also like