Python:上海三大运营商市场口碑如何?数据分析告诉你

根据国家规定,2019年11月底前在全国实施“携号转网”,上海自然也不会例外。对于上海三大运营商来说,“携号转网”既是一个挑战,也是一个机遇,能否抓住对于接下去3年的发展至关重要。在上海本土居民中,三大运营商的市场口碑到底如何,也将是影响“携号转网”结果的一个重要参考指标。本文通过爬虫技术,对本地部分网民对上海三大运营商的帖子主题进行收集并分析,给大家呈现一个最直观的结果。

一、目标寻找
本次爬取的网站是上海本地论坛:宽带山(https://club.kdslife.com/f_15.html)。
此论坛主要以上海本地男性网民为主,在本地有一定的影响力,能够反映出上海部分本地居民对三大运营商的感知。另外由于网站限制,对于部分帖子需要收藏后才能打开,所以本次爬取字段包括主题、人气(查看度)、发布人、发布时间,并考虑到时间因素,只爬取2018年1月1日之后的帖子。

二、数据爬取
《Python:上海三大运营商市场口碑如何?数据分析告诉你》
因为仅需要爬取搜索记录,所以不涉及到反爬技巧

import requests
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from wordcloud import WordCloud
import jieba

headers = { 
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
    'Host': 'club.kdslife.com'
}

'''第一步:爬取有关三大运营商在本地论坛KDS里近一年的帖子标题'''
def export_Info(yys, content):
    '''导出有关运营商的帖子信息'''
    with open(yys + '.txt', 'a', encoding='utf-8') as file:
        file.write(content + '\n')

def spider_yys():
    '''爬取三大运营商在本地论坛KDS里的帖子信息'''
    for y in yys:
        for j in range(40):
            url = r"https://club.kdslife.com/index.php?c=forum/search&m=main&fid=0&s_word=" + y + "&type=1&sort=post_time&page=" + str(j)
            r = requests.get(url=url, headers=headers)
            soup = BeautifulSoup(r.text, 'lxml')
            content = soup.find_all(name='li', attrs={ 'class': 'i2'})
            try:
                if str(content[0].find(name='span', attrs={ 'class': 'n6'}).string).startswith('17'): break
            except:
                break
            for i in range(len(content)):
                theme = content[i].find(name='a')['title'] #标题
                if '移动硬盘' in theme: continue
                if '移动支付' in theme: continue
                if '电信诈骗' in theme: continue
                popularity = content[i].find(name='span', attrs={ 'class': 'n2'}).string #人气
                presenters = content[i].find(name='a', attrs={ 'target': '_blank'}).string #发表人
                present_time = content[i].find(name='span', attrs={ 'class': 'n6'}).string #发布时间
                try:
                    if str(present_time).startswith('17'): break
                    new_content = theme + '\t' + popularity + '\t' + presenters + '\t' + present_time + '\t'
                    print(new_content)
                    export_Info(y, new_content)
                except:
                    continue

yys = ['电信', '移动', '联通']
spider_yys()               

爬下来的结果如图:
《Python:上海三大运营商市场口碑如何?数据分析告诉你》
三、数据整理与分析
通过pandas对数据进行剔除重复项、空值等操作,并做描述性统计:

def popularity_format(popularity):
    '''把点击量标准化,如1.1w改成11000'''
    if 'w' in str(popularity):
        pop_format = int(float(str(popularity).replace('w', '')) * 10000)
        return pop_format
        
yys = ['电信', '移动', '联通']
for y in yys:
    yys_file = y + '.txt'
    dx_news = pd.read_csv(yys_file, sep='\t', encoding='utf-8', engine='python', skipinitialspace=True,
                          usecols=[0, 1, 2, 3], names=['theme', 'popularity', 'presenters', 'present_time'], skiprows=1)
    dx_news.dropna(axis=0, inplace=True)
    dx_news.drop_duplicates(inplace=True)
    print('以下是{}帖子的相关数据:'.format(y))
    print('{}的主题数:{}'.format(y, dx_news.shape[0]))  # 主题数
    dx_news['popularity'] = dx_news['popularity'].astype(str).apply(popularity_format)
    popularity_sum = dx_news['popularity'].sum()
    print('{}的帖子热度和:{}'.format(y, popularity_sum))  # 帖子的关注度总和
    popularity_count = dx_news[['theme', 'popularity']].sort_values(by='popularity', ascending=False).head(3)
    print('{}点击量最大的3个帖子:\n {}'.format(y, popularity_count))  # 点击量最大的3个帖子
    presenters_count = dx_news.groupby('presenters').size().sort_values(ascending=False).head(3)
    print('{}发帖数量最多的3个发布者:\n {}'.format(y, presenters_count)) #发帖人发帖数量最多的3个

1、主题数比较:
《Python:上海三大运营商市场口碑如何?数据分析告诉你》
上海电信和上海移动的相关发帖量比较接近,上海联通则很少,这也可以从侧面反映出来上海地区三大运营商的市场占有率如何

2、帖子热度和比较:
《Python:上海三大运营商市场口碑如何?数据分析告诉你》
和主题数类似,但上海联通显得更少了

3、网友最关注的的3个帖子:
《Python:上海三大运营商市场口碑如何?数据分析告诉你》
1)、上海电信前三关注的帖子,第一个是说年费的,第二个是讲光猫破解(技术控?),第三个标题很奇怪,进去一看原来是讲排线乱的问题。看来电信的宽带还是比较受大家肯定的,只是排线乱的问题的确是需要解决一下;
2)、上海移动前三帖子其实用一个字就可以讲完了:送!
送宽带、送话费、送手机、送流量,用尽一切方法来绑定客户,对于电信宽带市场来说冲击力度很大;而且排名第一的帖子热度值近80万,虽然明显是一个营销广告贴,但效果还是达到了,老百姓还是吃这一套的!
3)、上海联通就比较可怜了,排名第一的还是一个校园卡的帖子,热度还比不上电信和移动的第三名

四、词云图
为了更直观地了解情况,使用jieba进行分词,再用wordcloud进行词图展现:

def drop_stopwords(content):
    '''先用jieba分词,然后去除停用词'''
    contents_clean = []
    content = content.strip()
    word_list = jieba.lcut(content)
    for word in word_list:
        try: word = word.replace('电信', '')
        except: pass
        if word in stopwords:
            continue
        if word.strip() == '': continue
        contents_clean.append(word)
        all_words.append(word)
    return contents_clean

yys = ['电信', '移动', '联通']
for y in yys:
    stopwords = pd.read_csv('stopwords.txt', engine='python', encoding='utf-8', sep='\r\n', names=['stopword']) #停用词
    stopwords = stopwords.stopword.values.tolist()
    yys_file = y + '.txt'
    dx_news = pd.read_csv(yys_file, sep='\t', encoding='utf-8', engine='python', skipinitialspace=True, usecols=[0, 1, 2, 3], names=['theme', 'popularity', 'presenters', 'present_time'], skiprows=1)
    all_words = []
    dx_news['theme'] = dx_news['theme'].astype(str).apply(drop_stopwords)
    df_all_words = pd.DataFrame({ 'all_words': all_words})
    words_count = df_all_words.groupby(by=['all_words'])['all_words'].agg({ 'count': np.size})
    words_count = words_count.reset_index().sort_values(by=['count'], ascending=False)
    wordcloud = WordCloud(scale=20, font_path='simhei.ttf', background_color='white', max_words=50, max_font_size=100, random_state=20)
    word_frequence = { x[0]: x[1] for x in words_count.head(100).values}
    wordcloud = wordcloud.fit_words(word_frequence)
    plt.imshow(wordcloud)
    plt.axis("off")
    # plt.show()
    wordcloud.to_file(y + '.jpg')

1、上海电信
《Python:上海三大运营商市场口碑如何?数据分析告诉你》
分析:上海电信给本地居民的主要印象还是“宽带”、“手机”、“十全十美”、“IPTV”、“到期”、“光猫”等,并没有跳出传统印象;同时对比上海移动和上海联通,“5G”的标签仅仅存在于左上一个不起眼的角落里,上海电信的“5G”宣传仍需努力。

2、上海移动
《Python:上海三大运营商市场口碑如何?数据分析告诉你》
分析:上海移动的主要关键词是“流量”、“宽带”、“送”、“免费”、“手机”,看来进攻策略是相当的明显,但是正如标签里的“套路”所说,免费的产品质量如何?“网络”、“服务”如何?这才是一个产品能否持续生存的关键。

3、上海联通
《Python:上海三大运营商市场口碑如何?数据分析告诉你》
分析:上海联通的主要关键词是“宽带”、“5G”、“校园卡”、“便宜”,对市场的抢占欲望不强,主要重心在于基础建设和校园发展。需要注意的是,受益于“老师我叫何同学”的一条VBlog,”5G”也变成了联通的一条显著标签,这值得我们思考:传统的营销手段是否已没落?剔除“东施效颦”般的劣质仿冒品,高质量的新型视频宣传是否已成为一条新的推广之道?

五、笔者小谈
1、本文的篇幅不长、代码不多,主要是因为刚学jieba分词和wordcloud的新技术,所以拿来练练手,只有最基础的描述性统计分析,不涉及到算法和机器学习,后续会思考如何提升;

2、正如我前文所说,携号转网既是一个挑战,也是一个机遇。市场瞬息万变,但是市民对于产品的追求就2个词:便宜+好用。但是对于三大运营商来说,国资委的考核指标是利润率,而利润率的主要指标则是收入和成本,如果一直用“送宽带、送话费、送手机、送流量”的方式,虽然短期内的确有较好的成绩,再配合内部成本压降,完成利润率等考核指标不难,也能有高发展量、高新增收入、高市场占有率等比较好的答卷。但长久之后,损失的却是企业内部的健康发展,最终受苦的仍然是广大百姓。

    原文作者:cyber_1987
    原文地址: https://blog.csdn.net/weixin_42029733/article/details/95759326
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞