Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ratings = 0 for review in hotel_data[ 'Reviews']: if cleanliness in review[ 'Ratings'] : ratings.append(int (review[ 'Ratings' I 'Cleanliness'])) # convert 'l' to 1, etc.
ratings = 0 for review in hotel_data[ 'Reviews']: if "cleanliness" in review[ 'Ratings'] : ratings.append(int (review[ 'Ratings' I 'Cleanliness'])) # convert 'l' to 1, etc. len (ratings) print("The average 'cleanliness' ratings of the reviews is (mean(ratings)}") Problem 8 (6 pts.): Iterate over all the reviews to create two lists: pol_data and serv_rating_data. 1. For each review that contains both a Service" rating and contains the word "staff", save the "Service" rating to serv_rating_data 2. Find the average sentiment polarity (like you did in Problem 7) and save it to pol_data. The two lists should have the same length (of 138). 3. Create a side by side box plot of each of the 5 ratings to show the range of values for each rating. (Note that no review containing "staff" in the comments received a rating of 2 . So only 4 box plots should show up.) import nltk #nltk. download('punkt') pol_data = 0 serv_rating_data = [] * TO DO: Iterate over all the reviews to build the lists 'pol_data' and 'serv_rating_data' TO DO: Find the reviews that contain both a "Service" rating and the word "staff" # and save them to the list 'serv_rating_data' * TO DO: Find the average sentiment polarity (like problem 7) and save it to 'pol_data' * TO DO: Verify 'pol_data' and 'serv_rating_data' each have a length of 138. Here are the first 5 elements of pol_data: 0.0, 0.375, 0.4, 0.4375, 0.1875, ... And the first 5 elements of serv_ratings_data: 4,5,5,5, 4, ... # TO DO: Create a side by side box plot of each of the ratings ratings = 0 for review in hotel_data[ 'Reviews']: if "cleanliness" in review[ 'Ratings'] : ratings.append(int (review[ 'Ratings' I 'Cleanliness'])) # convert 'l' to 1, etc. len (ratings) print("The average 'cleanliness' ratings of the reviews is (mean(ratings)}") Problem 8 (6 pts.): Iterate over all the reviews to create two lists: pol_data and serv_rating_data. 1. For each review that contains both a Service" rating and contains the word "staff", save the "Service" rating to serv_rating_data 2. Find the average sentiment polarity (like you did in Problem 7) and save it to pol_data. The two lists should have the same length (of 138). 3. Create a side by side box plot of each of the 5 ratings to show the range of values for each rating. (Note that no review containing "staff" in the comments received a rating of 2 . So only 4 box plots should show up.) import nltk #nltk. download('punkt') pol_data = 0 serv_rating_data = [] * TO DO: Iterate over all the reviews to build the lists 'pol_data' and 'serv_rating_data' TO DO: Find the reviews that contain both a "Service" rating and the word "staff" # and save them to the list 'serv_rating_data' * TO DO: Find the average sentiment polarity (like problem 7) and save it to 'pol_data' * TO DO: Verify 'pol_data' and 'serv_rating_data' each have a length of 138. Here are the first 5 elements of pol_data: 0.0, 0.375, 0.4, 0.4375, 0.1875, ... And the first 5 elements of serv_ratings_data: 4,5,5,5, 4, ... # TO DO: Create a side by side box plot of each of the ratings
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started