As can be seen, we can get the restaurant's per capita consumption, the number of reviews, recommended dishes, ratings (taste, environment, services) and other information for our analysis later. We climbed a total of 225 cities, 6,758 restaurants and 1.213 million reviews.
We intercept some of the core code:
def find_city_page (path): data = pd.read_excel (path) city_lobster_page = PD. DataFrame () Driver = Webdriver. Chrome () for I in range (0,len (data)): Try:js= ' window.open ("' +data[' city_lobster_url '][i]+ '") ' Driver.execute_script ( JS) bsobj = BeautifulSoup (Driver.page_source, ' html.parser ') bs = Bsobj.find_all (' A ', attrs={' class ': ' Pagelink '}) this_ city_lobster={' city_name ':d ata[' city_name '][i], ' Page_num ': max ([Int (l.text) for L in BS])} city_lobster_page = City_ Lobster_page.append (this_city_lobster,ignore_index=true) except:continue return city_lobster_page
After delineating the city of TOP20, we first look at the per capita consumption of TOP20 city crayfish
We found that service points are the same as environmental sorting, and they are highly correlated and conform to common cognition. At the same time can be seen in three points, the north of the four cities in Tianjin, Xian, Beijing, Qingdao, the indicators are in front of the position, of which Tianjin service and environment are in the first place.
Combined with the national small lobster heat, it seems that some contrary to everyone's cognition.
13 fragrant, garlic, spicy high ranking top three, according to the author's experience, this is basically in line with the overall taste of the choice of everyone. TOP20 in the egg yolk, white burns for the author is relatively unfamiliar, have tasted friends can share some of these taste experience.
After reading the taste, look at the lobster's good friends
PART4: Lobster Portrait
At present, the Internet companies are very common in the analysis of some population portraits, we borrow this concept here, but also for the crayfish to draw an exclusive portrait, the following two pictures are shown below are the word cloud and template artwork
Part of the word cloud drawing code is as follows:
# parse crayfish pictures back_color = Imread (' crayfish. jpg ') # parse the picture # parameter Configuration WC = Wordcloud (background_color= ' White ', # background color max_words=300, # Maximum number of words Mask=back_color, # with this parameter value plotted to draw the word cloud, when this parameter is not empty, width and height will be ignored max_font_size=100, # Displays the maximum value of the font font_path= "c:/windows/fonts/ Simhei.ttf ", # Solve the display font garbled problem, you can enter the c:/windows/fonts/directory to replace the font random_state=4, # for each word returns a PIL color #width = 2000, # Picture of the width #height = 1860 # The length of the picture) # Generate Word Cloud Wc.generate_from_frequencies (word_counts) by Encounter counter # Generate corresponding color image_colors = imagecolorgenerator based on color image (back_color) # Draw Word Cloud Plt.figure () plt.imshow (Wc.recolor (color_func=image_colors)) Plt.axis (' off ')
PART5: Special (HEI) color (AN) lobster
At the end of the article we put a few previous participle found in the characteristic taste lobster, perhaps the next net Red Lobster in which
Incoming group: 125240963 to get dozens of sets of PDFs Oh!
Beer crayfish, football World Cup! Use Python today to analyze where crayfish are best eaten.