<jupyter_start><jupyter_text>计算帖子数量；<jupyter_code>topic_url = csv.topic_url
topic_url_filter = [i for i in topic_url if str(i).split(':')[0] == 'https']
topic_nums = list(set(topic_url_filter))
print('帖子总数为：', len(topic_nums))<jupyter_output>帖子总数为： 88151<jupyter_text>计算每月发帖数量；<jupyter_code>time = csv.time
time_topicUrl = [[t, u] for t, u in zip(time, topic_url)]
time_topicUrl_filter = [i for i in time_topicUrl if str(i[1]).split(':')[0] == 'https']
topicUrl_time_filter_dict = dict([[i[1], i[0]] for i in time_topicUrl_filter])
topic_time = [i.split('/')[1] for i in list(topicUrl_time_filter_dict.values())]
topic_time_dict = dict(Counter(topic_time))
topic_time_dict_sorted = sorted([[int(i), j] for i, j in topic_time_dict.items()], key=lambda x:x[0])
#可视化每月发帖数量；

x = [i[0] for i in topic_time_dict_sorted]
y = [i[1] for i in topic_time_dict_sorted]

x_ = tuple([str(i) for i in x])

plt.plot(x, y, 'b*-')
plt.xticks(x, x_)
plt.yticks(fontsize=10)
plt.xlabel('Month')
plt.ylabel('Number of posts', fontsize=10)
#plt.legend()

plt.savefig(r'1.png', dpi=1000)

plt.show()

print('每月发帖数量为：', y)<jupyter_output><empty_output><jupyter_text>计算每天发帖数量；<jupyter_code>#计算哪天发帖最多；

topic_time_day = ['.'.join(i.split('/')[1:]) for i in topicUrl_time_filter_dict.values()]
topic_time_day_dict = dict(Counter(topic_time_day))
topic_time_day_dict_sorted = sorted([[i, j] for i, j in topic_time_day_dict.items()], key=lambda x:x[1], reverse=True)
#可视化每天发帖数量（前10）；

x = [i[0] for i in topic_time_day_dict_sorted[:10]]
y = [i[1] for i in topic_time_day_dict_sorted[:10]]

x_ = tuple([str(i) for i in x])

plt.plot(x, y, '^-')
plt.xticks(x, x_)
plt.yticks(fontsize=10)
plt.xlabel('Day')
plt.ylabel('Number of posts', fontsize=10)
#plt.legend()

plt.savefig(r'2.png', dpi=1000)

plt.show()

print('以天为粒度，发帖前数量为：', y)<jupyter_output><empty_output><jupyter_text>计算用户发帖数量分布；<jupyter_code>id_url = csv.id
topic_id = [[u, i] for i, u in zip(id_url, topic_url)]
topic_id_filter = [i for i in topic_id if str(i[0]).split(':')[0] == 'https']
id_topic_filter_dict = dict(topic_id_filter)
id_filter = sorted([[i, j]for i, j in dict(Counter(list(id_topic_filter_dict.values()))).items()], key=lambda x:x[1], reverse=True)

print('发帖数量前10的哈er：')
for i in id_filter[:100]:
    print(i)
print('共有', len(id_filter), '位用户发帖')<jupyter_output>共有 46922 位用户发帖<jupyter_text>计算回帖用户数量分布及最赞回复用户数量；<jupyter_code>reply_id = list(csv.reply_id)
topic_replyId= [[j, i] for i, j in zip(reply_id, topic_url)]
topic_replyId_dict = dict([i for i in topic_replyId if str(i[0]).split(':')[0] == 'https'])

topic_replyId_ = []
for key, value in topic_replyId_dict.items():
    v_re = re.split(r'["\']', value)
    v_re_ = []
    for v in v_re:
        if v not in ['[', ', ', ']', '[]']:
            v_re_.append(v)
    topic_replyId_.append([key, v_re_])

popular_idx = list(csv.popular_index)
topic_popularIdx = [[j, i] for i, j in zip(popular_idx, topic_url)]
topic_popularIdx_dict = dict([i for i in topic_popularIdx if str(i[0]).split(':')[0] == 'https'])

topic_replyIdList_dict = dict(topic_replyId_)

replyIdPopuAll_list = []
replyIdAll_list = []
for k, v in topic_popularIdx_dict.items():
    try:
        replyIdPopu_list = topic_replyIdList_dict[k][:int(v)]
        replyId_list = topic_replyIdList_dict[k][int(v):]
    except:
        continue
    replyIdPopuAll_list.append(replyIdPopu_list)
    replyIdAll_list.append(replyId_list)
    
replyIdPopuAll_list_ = sorted([[i, j] for i, j in dict(Counter([j for i in replyIdPopuAll_list for j in i])).items()], key=lambda x:x[1], reverse=True)
replyIdAll_list_ = sorted([[i, j] for i, j in dict(Counter([j for i in replyIdAll_list for j in i])).items()], key=lambda x:x[1], reverse=True)

print('最赞回复前20的哈er：')
for i in replyIdPopuAll_list_[:20]:
    print(i)
print('回复数量前20的哈er：')
for i in replyIdAll_list_[:20]:
    print(i)<jupyter_output>回复数量前20的哈er：
['https://www.douban.com/people/168329724/', 9256]
['https://www.douban.com/people/220599391/', 6261]
['https://www.douban.com/people/70132522/', 4332]
['https://www.douban.com/people/deadgirlheart/', 3365]
['https://www.douban.com/people/ppzj0531/', 2603]
['https://www.douban.com/people/130879171/', 2297]
['https://www.douban.com/people/161624149/', 2172]
['https://www.douban.com/people/143047320/', 1744]
['https://www.douban.com/people/152288544/', 1633]
['https://www.douban.com/people/29112941/', 1585]
['https://www.douban.com/people/148561478/', 1581]
['https://www.douban.com/people/67876697/', 1508]
['https://www.douban.com/people/198059162/', 1436]
['https://www.douban.com/people/193996802/', 1416]
['https://www.douban.com/people/168578270/', 1340]
['https://www.douban.com/people/LISTCHAINHASH/', 1324]
['https://www.douban.com/people/142225631/', 1310]
['https://www.douban.com/people/82986120/', 1267]
['https://www.douban.com/people/63850076/', 1259]
['https://www.do[...]<jupyter_text>计算帖子回应数量分布；<jupyter_code>responses_num = list(csv.responses_num)
topic_responseNum = [[j, i] for i, j in zip(responses_num, topic_url)]
topic_responseNum_dict = dict([i for i in topic_responseNum if str(i[0]).split(':')[0] == 'https'])

topic_replyIdNums_dict = dict([[i[0], len(i[1])] for i in topic_replyId_])

topic_responseNum_dict_ = []
for i, j in topic_responseNum_dict.items():
    try:
        j = int(j)
        topic_responseNum_dict_.append([i, j])
    except:
        continue

topic_responseNum_sorted = sorted([[i, j] for i, j in dict(topic_responseNum_dict_).items()], key=lambda x:x[1], reverse=True)
topic_responseNum_filter = [[i[0], i[1]] for i in topic_responseNum_sorted if topic_replyIdNums_dict[i[0]] > 2]

print('回复数量前17的帖子：')
for i in topic_responseNum_filter[:20]:
    print(i)
top2000 = len([i[0] for i in topic_responseNum_sorted if i[1] >= 2000])
top2000_1500 = len([i[0] for i in topic_responseNum_sorted if 1500 <= i[1] < 2000])
top1500_1000 = len([i[0] for i in topic_responseNum_sorted if 1000 <= i[1] < 1500])
top1000_500 = len([i[0] for i in topic_responseNum_sorted if 500 <= i[1] < 1000])
top500_0 = len([i[0] for i in topic_responseNum_sorted if i[1] < 500])
top500_400 = len([i[0] for i in topic_responseNum_sorted if 400 <= i[1] < 500])
top400_300 = len([i[0] for i in topic_responseNum_sorted if 300 <= i[1] < 400])
top300_200 = len([i[0] for i in topic_responseNum_sorted if 200 <= i[1] < 300])
top200_100 = len([i[0] for i in topic_responseNum_sorted if 100 <= i[1] < 300])
top100_0 = len([i[0] for i in topic_responseNum_sorted if 0 <= i[1] < 100])
topMax100 = len([i[0] for i in topic_responseNum_sorted if i[1] > 100])
fig, ax = plt.subplots(figsize=(6, 3), subplot_kw=dict(aspect="equal"))

recipe = ['>=100', '0-99']

data = [topMax100, top100_0]
#data_ = [top500_400, top400_300, top300_200, top200_100, top100_0]

wedges, texts = ax.pie(data, wedgeprops=dict(width=0.5), startangle=-40)

bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)
kw = dict(arrowprops=dict(arrowstyle="-"),
          bbox=bbox_props, zorder=0, va="center")

for i, p in enumerate(wedges):
    ang = (p.theta2 - p.theta1)/2. + p.theta1
    y = np.sin(np.deg2rad(ang))
    x = np.cos(np.deg2rad(ang))
    horizontalalignment = {-1: "right", 1: "left"}[int(np.sign(x))]
    connectionstyle = "angle,angleA=0,angleB={}".format(ang)
    kw["arrowprops"].update({"connectionstyle": connectionstyle})
    ax.annotate(recipe[i], xy=(x, y), xytext=(1.35*np.sign(x), 1.4*y),
                horizontalalignment=horizontalalignment, **kw)

ax.set_title('Distribution of posts based on the amount of responses')

plt.savefig(r'4.png', dpi=1000)

plt.show()<jupyter_output><empty_output><jupyter_text>计算哈er的发帖方式及回帖方式；<jupyter_code>topic_ways = list(csv.topic_ways)
topic_topicWays = [[j, i] for i, j in zip(topic_ways, topic_url)]
topic_responseNum_dict = dict([i for i in topic_topicWays if str(i[0]).split(':')[0] == 'https'])

appWay = [j for i, j in topic_responseNum_dict.items() if j == '来自 豆瓣App']

my_dpi=95
plt.figure(figsize=(480/my_dpi,480/my_dpi),dpi=my_dpi)
plt.pie(x=[2351, 85800],
        labels=['Client', 'Douban App'],
        colors=["#F08080", "#87CEEB"],
        autopct='%1.1f%%',
        explode=(0.2, 0),
       )
plt.savefig(r'3.png', dpi=1000)
plt.show()
reply_ways = list(csv.replyWays)
topic_replyWays = [[j, i] for i, j in zip(reply_ways, topic_url)]
topic_replyWays_dict = dict([i for i in topic_replyWays if str(i[0]).split(':')[0] == 'https'])

topic_replyWays_list = []

for k, v in topic_replyWays_dict.items():
    try:
        #v_re = re.split(r'["\']', v)
        v_re = [i for i in re.split(r'["\']', v) if i not in ['[', ', ', ']', '[]']]
        topic_replyWays_list.append([k, v_re])
    except:
        continue

replyWays_list = [j for i in topic_replyWays_list for j in i[1]]
Counter(replyWays_list)
data_ = [dict(Counter(replyWays_list))[''], dict(Counter(replyWays_list))['来自 豆瓣App']]

my_dpi=96
plt.figure(figsize=(480/my_dpi,480/my_dpi),dpi=my_dpi)
plt.pie(x=data,
        labels=['Client', 'Douban App'],
        colors=["#F08080", "#87CEEB"],
        autopct='%1.1f%%',
        explode=(0.2, 0),#某部分突出显示，值越大，距离中心越远，该法可解决饼图字体重叠的问题
       )
plt.savefig(r'5.png', dpi=1000)
plt.show()<jupyter_output><empty_output><jupyter_text>词云图；<jupyter_code>docs = list(csv.docs)
topic_docs = [[j, i] for i, j in zip(docs, topic_url)]
topic_docs_dict = dict([i for i in topic_docs if str(i[0]).split(':')[0] == 'https'])

words = []
for i in topic_docs_dict.values():
    try:
        word_list = list(jieba.cut(i))
    except:
        continue
    words.extend(word_list)

words_s = ' '.join(words)
 
wc = WordCloud(font_path=r'ZiZhiQuXiMaiTi-2.ttf',
               background_color='white',
               width=1000,
               height=800,
               ).generate(words_s)
#wc.to_file('hahaha.png')
plt.imshow(wc)
plt.axis('off')
plt.show()<jupyter_output><empty_output><jupyter_text>回复内容分析；<jupyter_code>reply_content = list(csv.reply_content)

topic_replyContent= [[j, i] for i, j in zip(reply_content, topic_url)]
topic_replyContent_dict = dict([i for i in topic_replyContent if str(i[0]).split(':')[0] == 'https'])
topic_replyContent_ = []
for key, value in topic_replyContent_dict.items():
    try:
        v_rc = re.split(r'["\']', value)
        v_rc_ = []
        for v in v_rc:
            if v not in ['[', ', ', ']', '[]']:
                v_rc_.append(v)
    except:
        v_rc_ = []
    topic_replyContent_.append([key, v_rc_])

topic_replyContent_filter_dict = dict(topic_replyContent_)

replyContent_all = []
for k, v in topic_popularIdx_dict.items():
    try:
        r_c = topic_replyContent_filter_dict[k][int(v):]
        replyContent_all.append(r_c)
    except:
        continue
        
replyContent_all_ = [j for i in replyContent_all for j in i]
reply_ha = [j for i in replyContent_all_ for j in i]
reply_ha.count('哈')
replyContent_all_idx = []
for k, v in topic_popularIdx_dict.items():
    try:
        r_c = topic_replyContent_filter_dict[k][int(v):]
        replyContent_all_idx.append([k, r_c])
    except:
        continue
url_haNum = []
for i in replyContent_all_idx:
    try:
        chs = []
        for j in i[1]:
            ch = [m for m in j].count('哈')
            chs.append(ch)
        url_haNum.append([i[0], max(chs)])
    except:
        url_haNum.append([i[0], 0])
sorted(url_haNum, key=lambda x:x[1], reverse=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17683894866819544, 'fraction_numerical': 0.0530075851120127, 'mean_word_length': 4.720988900100908, 'pattern_counts': {'":': 1, '<': 51, '<?xml version=': 0, '>': 38, 'https://': 20, 'lorem ipsum': 0, 'www.': 20, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '270498', 'license': 'MIT', 'n_tokens_mistral': 5163, 'n_tokens_neox': 4822, 'n_words': 884, 'path': 'data_vis.ipynb', 'repo_name': 'Captain-F/-', 'size': '11338'}