Restaurant Review Data Analysis and Visualization with Python and pyecharts
This tutorial demonstrates how to acquire, clean, and analyze online restaurant review data using Python, then create customized bar and pie charts with pyecharts, while also illustrating the use of Python's Counter for rating distribution analysis.
When a friend needed a data‑driven marketing plan for the restaurant industry, the author suggested starting with online reviews from platforms such as Meituan, Dianping, and Ele.me, and then built a Python demo to illustrate the workflow.
The demo begins by fetching a sample of Dianping reviews via an API, anonymising the store name and address, and converting the JavaScript‑style literals true/false/null to Python's True/False/None. The cleaned JSON is saved as review_data in a data.py file for easy import.
A second script analysis.py imports the data and verifies its structure. From the summarys list inside the data, the overall impression scores are extracted and visualised with a customised pyecharts bar chart. The X‑axis labels (e.g., "菜品健康", "牛肉赞", "回头客") and Y‑axis counts (e.g., 51, 32, 29) are obtained via list comprehensions:
summary_name_list = [i.get('summaryString') for i in summarys]
summary_count_list = [i.get('summaryCount') for i in summarys]The bar chart’s add_yaxis() call uses category_gap=80% to increase column spacing for clarity.
Next, the tutorial extracts individual star ratings (1–5 stars, represented as 10, 20, 30, 40, 50) from each review, builds a list, and applies collections.Counter to count occurrences:
all_star = [i.get('reviewDataVO').get('reviewData').get('star') for i in all_review]
stars = dict(Counter(all_star))The resulting dictionary, e.g., {30: 2, 50: 3, 10: 1, 20: 3, 35: 1} , provides the data for a pyecharts pie chart after converting keys and values to lists:
data = zip(list(stars.keys()), list(stars.values()))Both the bar and pie charts are rendered, showing that the sample restaurant receives mixed feedback, with a notable proportion of 2‑ and 3‑star ratings and relatively few 5‑star reviews.
Finally, the author combines the four generated charts into a single report, demonstrating how Python’s built‑in tools (like Counter) and the pyecharts library can be leveraged for quick, insightful data analysis that can evolve into a full commercial solution.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.