美文网首页PandasPandas.Numpy.pandas
观演用户小群体画像分析(python pandas)

观演用户小群体画像分析(python pandas)

作者: 正在看书的Sophie | 来源:发表于2019-08-13 18:32 被阅读3次

    已经完成的步骤:

    (1)针对每个项目打上了标签,如下(用excel 存取):

    中国经典芭蕾舞剧《红色娘子军》 舞剧,芭蕾舞剧,红军,经典

    孟京辉系列作品之《恋爱的犀牛》 话剧,爱情

    金士杰、刘若瑀主演《演员实验教室》 话剧,金士杰,时间,寻找自我

    (2)有指定的用户群体的观演记录,观演记录之间用逗号隔开,excel存取

    一位观众一条观演数据,如:

    中国经典芭蕾舞剧《红色娘子军》,孟京辉系列作品之《恋爱的犀牛》,金士杰、刘若瑀主演《演员实验教室》

    接下来:

    步骤一:读取文件

    customers = pd.read_excel(r'C:\Users\JiangMeng\Desktop\用户观演.xlsx') #打开用户观演统计表

    labels = pd.read_excel(r'C:\Users\JiangMeng\Desktop\2019项目标签.xlsx',sep = ',') #打开项目标签表

    customer_show = customers['项目'].str.split(',',expand=True) #统计观众看的项目,以逗号分隔

    步骤二:统计观众看过的项目,存入customerShows

    customerShows = pd.Series()

    for i_show in range(customer_show.shape[1]):

        s_show = pd.Series(customer_show[i_show])

        customerShows = customerShows.append(s_show)

    数据处理:

    customerShows = customerShows.dropna(axis=0, how='any') #去空值行

    search_num = customerShows.count() #统计到的项目数量

    customerShows = customerShows.reset_index(drop=True) #重置索引

    步骤三:合并指定项目的标签

    search_labels = pd.DataFrame()

    for i_search_num in range(search_num):

         i_search_label = (labels.query("项目名称=="+"'"+customerShows[i_search_num]+"'")                                     ['label']).str.split(',',expand=True)

        search_labels = search_labels.append(i_search_label)

    打印search_labels 如下:

    步骤四:#计算标签

    merge_labels = pd.Series()

    for i_label in range(search_labels.shape[1]):

       name_label = pd.Series(search_labels[i_label]).value_counts()

        merge_labels = merge_labels.add(name_label, fill_value = 0)

    print(merge_labels.sort_values(ascending=False)) # 统计这部分用户的标签

    打印如下:

    仅作为模板展示,选择的数量较少,可以看到这部分用户的观演记录中,更喜欢看的是经典话剧类的项目,更倾向于带有影视元素题材的项目。

    相关文章

      网友评论

        本文标题:观演用户小群体画像分析(python pandas)

        本文链接:https://www.haomeiwen.com/subject/tjnbjctx.html