已經(jīng)完成的步驟:
(1)針對(duì)每個(gè)項(xiàng)目打上了標(biāo)簽,如下(用excel?存仍奖印):
中國(guó)經(jīng)典芭蕾舞劇《紅色娘子軍》 舞劇,芭蕾舞劇,紅軍,經(jīng)典
孟京輝系列作品之《戀愛的犀牛》 話劇,愛情
金士杰桑驱、劉若瑀主演《演員實(shí)驗(yàn)教室》 話劇,金士杰,時(shí)間,尋找自我
(2)有指定的用戶群體的觀演記錄萍聊,觀演記錄之間用逗號(hào)隔開此衅,excel存取
一位觀眾一條觀演數(shù)據(jù),如:
中國(guó)經(jīng)典芭蕾舞劇《紅色娘子軍》,孟京輝系列作品之《戀愛的犀拍ⅲ》最域,金士杰镀脂、劉若瑀主演《演員實(shí)驗(yàn)教室》
接下來:
步驟一:讀取文件
customers = pd.read_excel(r'C:\Users\JiangMeng\Desktop\用戶觀演.xlsx') #打開用戶觀演統(tǒng)計(jì)表
labels = pd.read_excel(r'C:\Users\JiangMeng\Desktop\2019項(xiàng)目標(biāo)簽.xlsx',sep = ',') #打開項(xiàng)目標(biāo)簽表
customer_show = customers['項(xiàng)目'].str.split(',',expand=True) #統(tǒng)計(jì)觀眾看的項(xiàng)目,以逗號(hào)分隔
步驟二:統(tǒng)計(jì)觀眾看過的項(xiàng)目忘伞,存入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)
數(shù)據(jù)處理:
customerShows = customerShows.dropna(axis=0, how='any') #去空值行
search_num = customerShows.count() #統(tǒng)計(jì)到的項(xiàng)目數(shù)量
customerShows = customerShows.reset_index(drop=True) #重置索引
步驟三:合并指定項(xiàng)目的標(biāo)簽
search_labels = pd.DataFrame()
for i_search_num in range(search_num):
? ? ?i_search_label = (labels.query("項(xiàng)目名稱=="+"'"+customerShows[i_search_num]+"'")? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?['label']).str.split(',',expand=True)
? ? search_labels = search_labels.append(i_search_label)
打印search_labels?如下:
步驟四:#計(jì)算標(biāo)簽
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)) # 統(tǒng)計(jì)這部分用戶的標(biāo)簽
打印如下:
僅作為模板展示,選擇的數(shù)量較少,可以看到這部分用戶的觀演記錄中涮毫,更喜歡看的是經(jīng)典話劇類的項(xiàng)目蜓肆,更傾向于帶有影視元素題材的項(xiàng)目。