热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

python爬虫应用演示_[Python爬虫实战]使用pyecharts展示明星数据pytorch中文网

一、统计明星粉丝Top30统计从我们获取到的5万明星信息,可以统计出来粉丝数量排序以及展示,由于显示有限,我们只展示Top30ÿ

一、统计明星粉丝Top30统计

从我们获取到的5万明星信息,可以统计出来粉丝数量排序以及展示,由于显示有限,我们只展示Top30,通过折线图来展示

from pyecharts import Bar,Line

import MySQLdb

class MostFans:

def __init__(self):

self.title = "明星粉丝Top30统计"

self.vicetitle = "数据统计来源于微博"

def charts(self):

datasource = self.dataSource()

if datasource:

line = Line(self.title, self.vicetitle,width="100%")

line.add("粉丝数", datasource["name"], datasource["fans"], mark_point=["average"])

line.add("关注数", datasource["name"], datasource["follow"], is_smooth=True, mark_line=["max", "average"])

line.render()

else:

print("未获取到数据,无法统计!")

def dataSource(self):

db = MySQLdb.connect("数据库IP", "数据库账号", "数据库密码", "数据库", charset='utf8')

cursor = db.cursor()

sql &#61; "SELECT &#96;id&#96;,&#96;name&#96;,&#96;weibo_followers_count&#96;,&#96;weibo_follow_count&#96; FROM new_star WHERE weibo_id <> 1 GROUP BY weibo_id ORDER BY &#96;weibo_followers_count&#96; DESC LIMIT %s" % (30)

try:

cursor.execute(sql)

results &#61; cursor.fetchall()

lists &#61; {"name":[],"fans":[],"follow":[]}

for result in results:

lists["name"].append(result[1])

lists["fans"].append(result[2])

lists["follow"].append(result[3])

return lists

except:

return []

if __name__ &#61;&#61; &#39;__main__&#39;:

modeclass &#61; MostFans()

modeclass.charts()

上面我们将爬虫获取到的数据通过dataSource获取&#xff0c;然后通过charts方法进行统计。从图表中我们可以轻松的看出&#xff0c;谢娜以1010500000粉丝占排行榜第一&#xff0c;同时何炅以929600000粉丝排行第二&#xff0c;Angelababy以856600000排行第三。



推荐阅读
author-avatar
吴小彬x
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有