| 
                         可视化代码如下。 
- from pyecharts import Pie, Map, Line 
 -  
 -  
 - def create_gender(df): 
 -     # 全部用户 
 -     # df = df.drop_duplicates('id') 
 -     # 包含关键字用户 
 -     df = df[df['name'].str.contains("坤|蔡|葵|kun")].drop_duplicates('id') 
 -     # 分组汇总 
 -     gender_message = df.groupby(['gender']) 
 -     gender_com = gender_message['gender'].agg(['count']) 
 -     gender_com.reset_index(inplace=True) 
 -  
 -     # 生成饼图 
 -     attr = gender_com['gender'] 
 -     v1 = gender_com['count'] 
 -     # pie = Pie("微博评论用户的性别情况", title_pos='center', title_top=0) 
 -     # pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient="vertical", legend_pos="left", legend_top="%10") 
 -     # pie.render("微博评论用户的性别情况.html") 
 -     pie = Pie("微博评论用户的性别情况(昵称包含关键字)", title_pos='center', title_top=0) 
 -     pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient="vertical", legend_pos="left", legend_top="%10") 
 -     pie.render("微博评论用户的性别情况(昵称包含关键字).html") 
 
  
02 评论用户区域分布 
  
广东以8000+的评论用户居于首位,随后则是北京、山东,江苏,浙江,四川。 
这里也与之前网易云音乐评论用户的分布有点相似。 
更加能说明这几个地方的网民不少。 
可视化代码如下。 
- def create_map(df): 
 -     # 全部用户 
 -     df = df.drop_duplicates('id') 
 -     # 分组汇总 
 -     loc_message = df.groupby(['province']) 
 -     loc_com = loc_message['province'].agg(['count']) 
 -     loc_com.reset_index(inplace=True) 
 -  
 -     # 绘制地图 
 -     value = [i for i in loc_com['count']] 
 -     attr = [i for i in loc_com['province']] 
 -     map = Map("微博评论用户的地区分布图", title_pos='center', title_top=0) 
 -     map.add("", attr, value, maptype="china", is_visualmap=True, visual_text_color="#000", is_map_symbol_show=False, visual_range=[0, 7000]) 
 -     map.render('微博评论用户的地区分布图.html') 
 
                          (编辑:滁州站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |