2 微信文章发布时间分布

因为这里发现搜索到的文章会有2018年以前的,这里予以删除,并且验证剩下文章的发布时间。
毕竟信息讲究时效性,如果我搜索获取的都是老掉牙的信息,,就没什么意思了,更何况还是在一直在变化的互联网行业。
- import numpy as np
- import pandas as pd
- from pyecharts import Bar
-
- df = pd.read_csv('sg_articles.csv', header=None, names=["title", "article", "name", "date"])
-
- list1 = []
- list2 = []
- for j in df['date']:
- # 获取文章发布年份及月份
- time_1 = j.split('-')[0]
- time_2 = j.split('-')[1]
- list1.append(time_1)
- list2.append(time_2)
- df['year'] = list1
- df['month'] = list2
-
- # 选取发布时间为2018年的文章,并对其进行月份统计
- df = df.loc[df['year'] == '2018']
- month_message = df.groupby(['month'])
- month_com = month_message['month'].agg(['count'])
- month_com.reset_index(inplace=True)
- month_com_last = month_com.sort_index()
-
- attr = ["{}".format(str(i) + '月') for i in range(1, 12)]
- v1 = np.array(month_com_last['count'])
- v1 = ["{}".format(int(i)) for i in v1]
- bar = Bar("微信文章发布时间分布", title_pos='center', title_top='18', width=800, height=400)
- bar.add("", attr, v1, is_stack=True, is_label_show=True)
- bar.render("微信文章发布时间分布.html")
3 标题、文章开头词云
- from wordcloud import WordCloud, ImageColorGenerator
- import matplotlib.pyplot as plt
- import pandas as pd
- import jieba
-
- df = pd.read_csv('sg_articles.csv', header=None, names=["title", "article", "name", "date"])
-
- text = ''
- # for line in df['article'].astype(str):(前文词云代码)
- for line in df['title']:
- text += ' '.join(jieba.cut(line, cut_all=False))
- backgroud_Image = plt.imread('python_logo.jpg')
- wc = WordCloud(
- background_color='white',
- mask=backgroud_Image,
- font_path='C:WindowsFontsSTZHONGS.TTF',
- max_words=2000,
- max_font_size=150,
- random_state=30
- )
- wc.generate_from_text(text)
- img_colors = ImageColorGenerator(backgroud_Image)
- wc.recolor(color_func=img_colors)
- plt.imshow(wc)
- plt.axis('off')
- # wc.to_file("文章.jpg")(前文词云代码)
- wc.to_file("标题.jpg")
- print('生成词云成功!')

公众号文章标题词云,因为是以Python这个关键词去搜索的,那么必然少不了Python。
然后词云里出现的的爬虫,数据分析,机器学习,人工智能。就便知道Python目前的主要用途啦! (编辑:威海站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|