<jupyter_start><jupyter_text>review.json<jupyter_code># review.json: Contains full review text data including the user_id that wrote the review and the business_id the review is written for.
review_rdd = sc.textFile(review_file_path, 240)
review_rdd.take(1)
# The total number of reviews 
n_review = review_rdd \
    .map(lambda r: 1) \
    .reduce(lambda a, b: a + b)

    
# The number of distinct users who wrote reviews
user_count = review_rdd \
        .map(lambda r: (json.loads(r)['user_id'], 1)) \
        .reduceByKey(lambda a, b: a + b).cache()
n_user = user_count \
    .map(lambda r : 1) \
    .reduce(lambda a, b: a + b)
    
    
# The top 10 users who wrote the largest numbers of reviews and the number of reviews they wrote
top10_user = user_count \
        .sortBy(lambda r: (-r[1], r[0])) \
        .take(10)
# The number of distinct businesses that have been reviewed 
business_count = review_rdd \
    .map(lambda r: (json.loads(r)['business_id'], 1)) \
    .reduceByKey(lambda a, b: a + b, 1).cache()
    
# The top 10 businesses that had the largest numbers of reviews and the number of reviews they had 
top10_business = business_count \
    .sortBy(lambda r: (-r[1], r[0])) \
    .take(10)
print("number of reviews: %d \n" % n_review)
print("number of users who has written at least one review on yelp: %d \n" % n_user)
print("top 10 active users (user_id, count): ")
print(*top10_user, sep='\n')
print("\ntop 10 popular businesses (business_id, count): ")
print(*top10_business, sep='\n')
"""
TODO: 

+ business_id ---> business_name using business.json (find top 10 popular businesses)

++ visualization: bar chart etc.

- What categories are they in? 

- What about in different states?

- their corresponding avg stars?


"""<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup