day14-Douyin user data analysis

1. Data Overview

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
#解决matplotlib库中的字体设置和Unicode minus问题
plt.rcParams["font.family"] = "SimHei"
plt.rcParams["axes.unicode_minus"] = False
data=pd.read_csv('./data/douyin_dataset.csv')
data

Insert image description here

  • Field meaning
    • The first column is an undefined field, which is sequential but not continuous. It may be a processed data set.
    • uid: user id
    • user_city: the city where the user is located
    • item_id: work id
    • author_id: author id
    • item_city: work city
    • channel: the source from which to view the work
    • finish: Whether you have finished browsing the works
    • like: Do you like the work?
    • music_id: music id
    • duration_time: duration of the work (seconds)
    • real_time: work release time
    • H: current hour
    • date: current date

2. Data cleaning

data.info()

Insert image description here

2.1 Missing values

#判断缺失值并按照行列统计
data.isnull().sum()

Insert image description here

2.2 Duplicate data

#判断是否有重复数据
data.duplicated().sum()

No duplicate data

2.3 Modify column names

colNameDict = {
    
    
    'Unnamed: 0': 'ID',
    'uid': '用户id',
    'user_city': '用户所在城市',
    'item_id': '作品id',
    'author_id': '作者id',
    'item_city': '作品城市',
    'channel': '观看到该作品的来源',
    'finish': '是否浏览完作品',
    'like': '是否对作品点赞',
    'music_id': '音乐id',
    'duration_time': '作品时长 s',
    'real_time': '作品发布时间',
    'H': '当前小时',
    'date': '当前日期'
}

data = data.rename(columns=colNameDict)
data

Insert image description here

2.4 Object conversion of data

data['作品发布时间']=pd.to_datetime(data['作品发布时间'])
data['当前日期']=pd.to_datetime(data['当前日期'])
data
data.info()

Insert image description here

3. Data analysis and visualization

3.1 Statistics of daily views, daily users, daily authors and daily works

df_group=data.groupby(by='当前日期')
"""日播放量"""
df_id=df_group['ID'].count()
df_id

"""日用户量"""
df_uid=df_group['用户id'].nunique()  # 返回不同值的数据个数
df_uid

"""日作者量"""
df_author=df_group['作者id'].nunique()  # 返回不同值的数据个数
df_author

"""日作品量"""
df_item=df_group['作品id'].nunique()   # 返回不同值的数据个数
df_item

#unique() 方法返回的是该列中的所有唯一值组成的列表,而 nunique() 方法返回的是每个分类组中的唯一值数量。

3.2 Drawing

plt.figure(figsize=(20,12),dpi=100)
x=df_id.index  # 时间作为x轴

ax1=plt.subplot(411)  # 4-> 一共绘图4张,11-> 第一列第一张
plt.plot(x,df_id.values)
plt.ylabel('日播放量')
plt.title('统计日播放量,日用户量,日作者量,日作品量')

# sharex=ax1 共享ax1的X轴
plt.subplot(412, sharex=ax1)   # 一共要绘制4个图, 12 --> 第一列第二张
plt.plot(x, df_uid.values)
plt.ylabel('日用户量')


# sharex=ax1 共享ax1的X轴
plt.subplot(413, sharex=ax1)   # 一共要绘制4个图, 13 --> 第一列第三张
plt.plot(x, df_author.values)
plt.ylabel('日作者量')

# sharex=ax1 共享ax1的X轴
plt.subplot(414, sharex=ax1)   # 一共要绘制4个图, 14 --> 第一列第四张
plt.plot(x, df_item.values)
plt.ylabel('日作品量')

plt.savefig('./data/抖音日数据统计图2.png')

Insert image description here

#显示作品id每个值出现的次数
data['作品id'].value_counts()

Insert image description here

3.3 Analyze the influence of top50 authors on the platform

author_50 = data['作者id'].value_counts().iloc[:50]
author_50

# 取出作品播放前50作者的id
cols_outhor = author_50.index
cols_outhor

# 统计每个top50作者的作品数量
# 用"作者id"分组, 取每个分组的"作品id", nunique取不重复的数据个数, 根据行索引取值
item_count = data.groupby('作者id')['作品id'].nunique()[cols_outhor]
item_count

# 取播放量排名前50作者的点赞平均数
authou_star_mean = data.groupby('作者id')['是否对作品点赞'].mean()[cols_outhor]
authou_star_mean

# 统计top50作者的播放率
author_player = data['作者id'].value_counts().sort_values(ascending=False)[cols_outhor] / len(data['ID'])
author_player
"""绘图"""
x = [str(i) for i in list(author_50.index)]

# 绘制播放量排名前50作者的作品数量
fig, ax1 = plt.subplots(figsize=(18, 8))
color = 'blue'
ax1.bar(x, item_count.values, color=color)
ax1.set_xlabel('作者id')
ax1.set_ylabel('作品数量', color=color)
ax1.tick_params(axis='y', labelcolor=color)  # 设置Y轴颜色


# 绘制播放量排名前50作者的点赞平均数
ax2 = ax1.twinx()  #  共享X轴
color = 'red'
ax2.plot(x, authou_star_mean.values, color=color)
ax2.set_ylabel('作品点赞平均数', color=color)
ax2.tick_params(axis='y', labelcolor=color)  # 设置Y轴颜色

# 绘制播放量排名前50作者的播放率
ax3 = ax2.twinx()  #  共享X轴
color = 'green'
ax3.plot(x, author_player.values, color=color)
ax3.set_ylabel('作品播放率', color=color)
ax3.tick_params(axis='y', labelcolor=color)  # 设置Y轴颜色

Insert image description here

3.4 Analysis of work sources

"""作品来源统计"""
channel = data['观看到该作品的来源'].value_counts()
channel

Insert image description here

plt.pie(
    x=channel.values,
    labels=[f'{
      
      char}渠道' for char in channel.index],
    autopct='%.2f%%'
)

Insert image description here

# 取播放量排名前10的音乐id
music_10 = data['音乐id'].value_counts().head(10)
music_10

x = [str(char) for char in music_10.index]
plt.bar(x, music_10.values)

# 数量排名前十的背景音乐ID分别是:22、220、25、68、110、33、468、57、43、238

Insert image description here

str(music_10.index)
music_10.values

Insert image description here

3.5 Analysis of work duration

# 不同时长作品的播放量
data_time = data.groupby('作品时长 s')['用户id'].count()

# 不同作品时长的作品量
data_time_item = data.groupby('作品时长 s')['作品id'].nunique()
data_time_item

Insert image description here

"""绘图"""
fig, ax1 = plt.subplots(figsize=(18, 8))
color = 'red'
ax1.set_title('作品不同时长和播放量与作品分布情况')
ax1.set_xlabel('时长/s')
ax1.set_ylabel('播放量', color=color)
ax1.plot(data_time.index, data_time.values, color=color)

ax2 = ax1.twinx()  #  共享X轴
color = 'blue'
ax2.set_ylabel('作品量', color=color)
ax2.plot(data_time_item.index, data_time_item.values, color=color)
ax2.set_xlim(0, 50)  # 限制x轴长度

Insert image description here

3.3 Analysis of work release time

# 统计不同作品发布时间的播放量
data_time = data.groupby('当前小时')['ID'].count()
data_time

# 不同作品发布时间的作品量
data_time_item = data.groupby('当前小时')['作品id'].nunique()
data_time_item

Insert image description here

"""绘图"""
fig, ax1 = plt.subplots(figsize=(18, 8))
color = 'red'
ax1.set_title('作品不同发布时间(24H)的播放量与作品数量的分布情况')
ax1.set_xlabel('发布时间(H)')
ax1.set_ylabel('播放量', color=color)
ax1.plot(data_time.index, data_time.values, color=color)

ax2 = ax1.twinx()  #  共享X轴
color = 'blue'
ax2.set_ylabel('作品量', color=color)
ax2.plot(data_time_item.index, data_time_item.values, color=color)

Insert image description here

4. Summary

4.1 Platform

  • Increase promotion activities: attract new users and maintain old users
  • Increase author incentive mechanism: stimulate authors to publish their works
  • You can consider expanding traffic channels: Attract new users to join

4.2 Author

  • Channels: 0
  • Background music: The top ten background music IDs are: 22, 220, 25, 68, 110, 33, 468, 57, 43, 238
  • Duration of work: preferably around 7-12S, no more than around 22S
  • Work release time: 19-0-5, the traffic pool for works released during this time period will be relatively large
  • Actively participate in platform activities

Guess you like

Origin blog.csdn.net/m0_73678713/article/details/134577384