分析斗鱼弹幕礼物发送情况

分析斗鱼弹幕礼物发送情况

一.数据来源
python抓取斗鱼直播间3168536的弹幕获得
二.数据处理
对得到的数据维度建模、ETL过程最终得到事实表dw_fact_analysis,取2017-12-17日 17时 ~ 24时直播弹幕数据
三.描述性分析
1.房间内每5分钟观众赠送礼物数量
SQL、PYTHON代码部分:

select 
    date_format(data_date, '%Y-%m-%d %H') as date_date, CAST(floor(date_format(data_date, '%i')/5) as signed) as times, count(*) as 'count'
from 
    dw_fact_analysis
where data_date between str_to_date('12/17/2017 17:00:00', '%m/%d/%Y %H:%i:%s') and  str_to_date('12/17/2017 23:59:59', '%m/%d/%Y %H:%i:%s')
group by date_date,times
order by date_date,times asc
x = df.index
y = df['count']
plt.figure(figsize=(10, 5))
plt.plot(x, y, '')
print(df['count'].mean())
print(df['count'].median())
plt.title(u'每5分钟礼物数量', fontproperties=font_set)
plt.xlabel(u'times')
plt.ylabel(u'count(gift)')

通过结果发现在时间段内赠送礼物最多为6939,最少为138
平均赠送数量为920.5
赠送礼物的中位数为582.5
分析斗鱼弹幕礼物发送情况_第1张图片

  1. 赠送礼物人数情况
    SQL、PYTHON代码部分:
select 
     count(user_code) as person, gift_code, user_value
from dw_fact_analysis
where data_date between str_to_date('12/17/2017 17:00:00', '%m/%d/%Y %H:%i:%s') and  str_to_date('12/17/2017 23:59:59', '%m/%d/%Y %H:%i:%s')
and user_value <> 'null'
group by gift_code
plt.figure(figsize=(10, 5))
df.reset_index()
df.set_index('gift_code', inplace=True)
df[['person']].plot(kind='bar')
plt.title(u'每种礼物赠送人数', fontproperties=font_set)
plt.xlabel(u'gift_code')
plt.ylabel(u'count(person)')

通过结果发现礼物编号1143赠送人数最多,其次为编号为520的礼物分析斗鱼弹幕礼物发送情况_第2张图片

  1. 礼物收益情况
    SQL、PYTHON代码部分:
select 
    round(sum(user_value), 2) as index_value, gift_code
from dw_fact_analysis 
where data_date between str_to_date('12/17/2017 17:00:00', '%m/%d/%Y %H:%i:%s') and  str_to_date('12/17/2017 23:59:59', '%m/%d/%Y %H:%i:%s')
group by gift_code
having index_value <> 'null'
df.reset_index()
df.set_index('gift_code', inplace=True)
df[['index_value']].plot(kind='bar', figsize=(6, 8))
plt.title(u'每种礼物收益情况', fontproperties=font_set)
plt.xlabel(u'gift_code')
plt.ylabel(u'count(price)')

通过结果发现收益前三的礼物编号为1005、1143、1115,与分析结果2比较,其编号1143礼物赠送最多但主播收益却不为最高,编号1005礼物赠送人数量最少但主播收益最大,说明大多数人赠送的都是比较廉价的礼物

分析斗鱼弹幕礼物发送情况_第3张图片

四.探索性分析
1.送了一次礼物的人是否还会送第二次

select count(*) from (
select 
    user_code, count(hit_type_code)
from dw_fact_analysis
where data_date between str_to_date('2017-12-17 17:00:00', '%Y-%m-%d %H:%i:%s') and str_to_date('2017-12-17 23:00:00', '%Y-%m-%d %H:%i:%s') 
and hit_type_code >='2'
group by user_code
order by user_code
) t1

select count(distinct user_code) from dw_fact_analysis

通过结果发现在93951人中, 只有5390 人第二次赠送了礼物

你可能感兴趣的:(数据仓库学习)