2.7、词云图可视化:
【display_address】、【street_address】、【features】
设计思路
核心代码
from wordcloud import WordCloud
text = ''
text_da = ''
text_street = ''
#text_desc = ''
for ind, row in train.iterrows():
for feature in row['features']:
text = " ".join([text, "_".join(feature.strip().split(" "))])
text_da = " ".join([text_da,"_".join(row['display_address'].strip().split(" "))])
text_street = " ".join([text_street,"_".join(row['street_address'].strip().split(" "))])
#text_desc = " ".join([text_desc, row['description']])
text = text.strip()
text_da = text_da.strip()
text_street = text_street.strip()
#text_desc = text_desc.strip()
plt.figure(figsize=(12,6))
wordcloud = WordCloud(background_color='white', width=600, height=300, max_font_size=50, max_words=40).generate(text)
wordcloud.recolor(random_state=0)
plt.imshow(wordcloud)
plt.title("features: Wordcloud for features", fontsize=30)
plt.axis("off")
plt.show()
# wordcloud for display address
plt.figure()
wordcloud = WordCloud(background_color='white', width=600, height=300, max_font_size=50, max_words=40).generate(text_da)
wordcloud.recolor(random_state=0)
plt.imshow(wordcloud)
plt.title("display_address: Wordcloud for Display Address", fontsize=30)
plt.axis("off")
plt.show()
# wordcloud for street address
plt.figure()
wordcloud = WordCloud(background_color='white', width=600, height=300, max_font_size=50, max_words=40).generate(text_street)
wordcloud.recolor(random_state=0)
plt.imshow(wordcloud)
plt.title("street_address: Wordcloud for Street Address", fontsize=30)
plt.axis("off")
plt.show()