【Python有趣打卡】微博APP榜单爬虫,尽知天下事(二)
2019-03-07 18:12
836 查看
【Python有趣打卡】微博APP榜单爬虫,尽知天下事(二)
今天继续接上学习微博热榜爬虫!不过已经完成了爬虫工作,今天主要是学习对之前爬取下来的数据进行数据分析!原创:罗罗攀(公众号:luoluopan1)学习Python有趣|微博APP爬虫,尽知天下事。
打开之前爬取的csv文件~开心
结果都是乱码,破坏我学习的心情,不过没关系
CSV打开乱码解决办法
方法一:
新建一个excel文件~
就可以啦~~
方法一:
直接用notepad++打开csv,编码→转为utf-8,点击保存,贼方便!!!!!
读取文件 ##### 用户分析
1.用户频次分析这里要用到 pyecharts
Echarts是百度公司出的,可以做炫酷的动态图,大神陈建东将echarts通过Python实现,设计了pyecharts库。
https://github.com/pyecharts/pyecharts
用到的方法是WordCloud.add() 方法签名
user = df['user'].value_counts() from pyecharts import WordCloud %matplotlib inline #魔法函数 一定要加上! wc = WordCloud(width=800, height=620) wc.add("f", list(user.index), list(user), word_size_range=[20, 80]) wc
又有问题了???抓狂,再去搜一下原因
解决办法:https://blog.csdn.net/zqs305082800/article/details/84581299
df['province'] = df['location'].str.split(' ').str[0] province = df['province'].value_counts() from pyecharts import Bar bar = Bar('地区分布情况') bar.add("", list(province[:10].index), list(province[:10]),xaxis_interval=0,xaxis_rotate=20,xaxis_margin=8,is_label_show=True) bar
3.用户性别分布
gender = df['gender'].value_counts() from pyecharts import Pie pie = Pie("性别分布") pie.add("", ['男性','女性'], list(gender), is_label_show=True) pie
4.粉丝数排名
data4 = df.drop_duplicates('user') #去除重复项 data4 = data4.sort_values(by='followers',ascending=False 20000 )[:10] data4 from pyecharts import Bar bar = Bar('粉丝前十') bar.add("", list(data4['user']), list(data4['followers']),xaxis_interval=0,xaxis_rotate=20,xaxis_margin=8,is_label_show=True) bar
5.发布时间分布
df['hour'] = df['created_time'].str.split(':').str[0].str.split(' ').str[-1] hour = df['hour'].value_counts() hour = hour.sort_index() from pyecharts import Line attr = list(hour.index) v = list(hour) line = Line("发布时间分布") line.add("", attr, v) line
5.榜单内容分词统计
str_data = '' for i in range(df.shape[0]): str_data = str_data + str(df.iloc[i,4]) str_data import jieba.analyse tags = jieba.analyse.extract_tags(str_data, topK=50, withWeight=True) label = [] attr = [] for item in tags: print(item[0]+'\t'+str(int(item[1]*1000))) label.append(item[0]) attr.append(int(item[1]*1000))
from pyecharts import WordCloud wordcloud = WordCloud(width=800, height=620) wordcloud.add("", label[3:], attr[3:], word_size_range=[20, 100]) wordcloud
相关文章推荐
- Python爬虫案例3:爬取房天下房价等各种信息
- 使用python/casperjs编写终极爬虫-客户端App的抓取
- python爬虫入门 实战(四)---爬“榜姐”话题微博及热门评论
- 使用python/casperjs编写终极爬虫-客户端App的抓取
- Python爬虫抓取手机APP的传输数据
- Python爬虫工程师必学 App数据抓取实战
- Python爬虫实现半自动发微博
- python爬虫之追女神监督微博信息
- 使用python/casperjs编写终极爬虫-客户端App的抓取
- Fiddler抓包---手机APP--python爬虫 基本设置和操作
- python--爬虫微博热门数据
- python爬虫(一):模拟登陆微博
- 使用python/casperjs编写终极爬虫-客户端App的抓取
- [Python爬虫] Selenium爬取新浪微博客户端用户信息、热点话题及评论 (上)
- python 网络爬虫——爬取小米应用商店排名前100App
- Python微博地点签到大数据实战(三)大数据利器:爬虫
- 最新Python新浪微博爬虫2014-07
- 最新Python 爬虫工程师必学 App数据抓取实战分享
- Python爬虫:抓取手机APP的数据
- python爬虫批量抓取新浪微博用户ID及用户信息、微博内容