加入收藏 | 设为首页 | 会员中心 | 我要投稿 威海站长网 (https://www.0631zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > 网站设计 > 教程 > 正文

Python数据可视化:Python大佬有哪些?

发布时间:2018-12-07 08:32:41 所属栏目:教程 来源:法纳斯特
导读:有态度地学习 之前讲了代理池以及Cookies的相关知识,这里针对搜狗搜索微信公众号文章的爬取,将它俩实践一下。 在崔大的书里面,他是用代理IP来应对搜狗的反爬措施,因为同一IP访问网页过于频繁,就会跳转验证码页面。 不过时代在进步,搜狗搜索的反爬也

2 微信文章发布时间分布

Python数据可视化:Python大佬有哪些?

因为这里发现搜索到的文章会有2018年以前的,这里予以删除,并且验证剩下文章的发布时间。

毕竟信息讲究时效性,如果我搜索获取的都是老掉牙的信息,,就没什么意思了,更何况还是在一直在变化的互联网行业。

  1. import numpy as np 
  2. import pandas as pd 
  3. from pyecharts import Bar 
  4.  
  5. df = pd.read_csv('sg_articles.csv', header=None, names=["title", "article", "name", "date"]) 
  6.  
  7. list1 = [] 
  8. list2 = [] 
  9. for j in df['date']: 
  10.     # 获取文章发布年份及月份 
  11.     time_1 = j.split('-')[0] 
  12.     time_2 = j.split('-')[1] 
  13.     list1.append(time_1) 
  14.     list2.append(time_2) 
  15. df['year'] = list1 
  16. df['month'] = list2 
  17.  
  18. # 选取发布时间为2018年的文章,并对其进行月份统计 
  19. df = df.loc[df['year'] == '2018'] 
  20. month_message = df.groupby(['month']) 
  21. month_com = month_message['month'].agg(['count']) 
  22. month_com.reset_index(inplace=True) 
  23. month_com_last = month_com.sort_index() 
  24.  
  25. attr = ["{}".format(str(i) + '月') for i in range(1, 12)] 
  26. v1 = np.array(month_com_last['count']) 
  27. v1 = ["{}".format(int(i)) for i in v1] 
  28. bar = Bar("微信文章发布时间分布", title_pos='center', title_top='18', width=800, height=400) 
  29. bar.add("", attr, v1, is_stack=True, is_label_show=True) 
  30. bar.render("微信文章发布时间分布.html") 

3 标题、文章开头词云

  1. from wordcloud import WordCloud, ImageColorGenerator 
  2. import matplotlib.pyplot as plt 
  3. import pandas as pd 
  4. import jieba 
  5.  
  6. df = pd.read_csv('sg_articles.csv', header=None, names=["title", "article", "name", "date"]) 
  7.  
  8. text = '' 
  9. # for line in df['article'].astype(str):(前文词云代码) 
  10. for line in df['title']: 
  11.     text += ' '.join(jieba.cut(line, cut_all=False)) 
  12. backgroud_Image = plt.imread('python_logo.jpg') 
  13. wc = WordCloud( 
  14.     background_color='white', 
  15.     mask=backgroud_Image, 
  16.     font_path='C:WindowsFontsSTZHONGS.TTF', 
  17.     max_words=2000, 
  18.     max_font_size=150, 
  19.     random_state=30 
  20. wc.generate_from_text(text) 
  21. img_colors = ImageColorGenerator(backgroud_Image) 
  22. wc.recolor(color_func=img_colors) 
  23. plt.imshow(wc) 
  24. plt.axis('off') 
  25. # wc.to_file("文章.jpg")(前文词云代码) 
  26. wc.to_file("标题.jpg") 
  27. print('生成词云成功!') 

Python数据可视化:Python大佬有哪些?

公众号文章标题词云,因为是以Python这个关键词去搜索的,那么必然少不了Python。

然后词云里出现的的爬虫,数据分析,机器学习,人工智能。就便知道Python目前的主要用途啦!

(编辑:威海站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读