Home  >  Article  >  Backend Development  >  Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels

Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels

Python当打之年
Python当打之年forward
2023-08-10 15:47:371091browse


ADX's full English name is "Ad Exchange", which is a large-scale trading platform that aggregates various media traffic. In this issue, we will analyze the advertising platforms of game companies to see which media platforms game companies like to advertise on. Hope to have some insights You helped.

涉及到的内容:
re — 正则表达式
pandas — 数据处理
collections — 数据统计
pyecharts - data visualization


1. Import module

#Code:

import re
import pandas as pd 
from collections import Counter
from pyecharts.charts import Line
from pyecharts.charts import Pie
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType
from pyecharts.charts import WordCloud
from pyecharts.globals import SymbolType
If the module is missing, just install it with pip.

2. pandas数据处理

2.1 读取数据 
df = pd.read_excel('games.xlsx')
df.head(3)
结果:

Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels

2.2 浏览数据信息 

df.info()

效果:

Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels

2.3 查看有无空值 

df.isnull().sum()

效果:

Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels


3. Collections数据统计

3.1 统计广告位平台 

ads = df['广告位'].values.tolist()
mediastr = ' '.join(ads)
medialist = re.findall('\(\'(.*?)\'', mediastr)
ac = Counter(medialist)

结果:

Counter({'今日头条': 1186, '抖音': 1098, '抖音火山版': 1089, '西瓜视频': 1087, '穿山甲联盟': 855, '腾讯新闻': 600, '天天快报': 585, '腾讯视频': 579, '优量广告': 507, '腾讯QQ': 489, 'QQ浏览器': 483, '快手': 393, '手机百度': 357, '爱奇艺': 349, '好看视频': 317, '网易新闻': 313, '虎扑': 302, 'UC头条': 227, '糗事百科': 222, '微信': 155, '华为浏览器': 132, '优酷视频': 65, '百度贴吧': 49, 'taptap': 38, 'Bilibili': 29, '知乎': 25, '新浪微博': 11, '全民小视频': 11, 'WiFi万能钥匙': 5})

3.2 广告平台列表、集合、字典 

print(list(ac))
print('\n')
print(set(ac))
print('\n')
print(dict(ac))

结果

['穿山甲联盟', '快手', '今日头条', '天天快报', '腾讯视频', '抖音火山版', '抖音', '西瓜视频', '优量广告', 'QQ浏览器', '腾讯新闻', '网易新闻', 'UC头条', '手机百度', '腾讯QQ', '好看视频', '爱奇艺', '百度贴吧', '虎扑', '优酷视频', '知乎', '糗事百科', '微信', '华为浏览器', 'Bilibili', '新浪微博', 'taptap', '全民小视频', 'WiFi万能钥匙']


{'全民小视频', 'QQ浏览器', '天天快报', '快手', '微信', '抖音', '百度贴吧', 'WiFi万能钥匙', '知乎', '华为浏览器', '网易新闻', '优量广告', '新浪微博', '西瓜视频', 'taptap', '优酷视频', '好看视频', 'UC头条', '抖音火山版', '糗事百科', '腾讯QQ', '手机百度', '虎扑', '爱奇艺', '今日头条', '穿山甲联盟', '腾讯新闻', '腾讯视频', 'Bilibili'}


{'穿山甲联盟': 855, '快手': 393, '今日头条': 1186, '天天快报': 585, '腾讯视频': 579, '抖音火山版': 1089, '抖音': 1098, '西瓜视频': 1087, '优量广告': 507, 'QQ浏览器': 483, '腾讯新闻': 600, '网易新闻': 313, 'UC头条': 227, '手机百度': 357, '腾讯QQ': 489, '好看视频': 317, '爱奇艺': 349, '百度贴吧': 49, '虎扑': 302, '优酷视频': 65, '知乎': 25, '糗事百科': 222, '微信': 155, '华为浏览器': 132, 'Bilibili': 29, '新浪微博': 11, 'taptap': 38, '全民小视频': 11, 'WiFi万能钥匙': 5}

3.3 广告平台投放前10的平台 

ac.most_common(10)

结果:

Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels

3.4 广告平台投放后10的平台 

ac.most_common()[:-10-1:-1]

结果:

Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels


4. tions数据统计Pyecharts可视化

4.1 游戏类型占比饼图TOP30 

代码:

g_type = df['游戏类型'].values.tolist()
g_typestr = '、'.join(g_type)
g_typelist = g_typestr.split('、')
g_typelist
gc = Counter(g_typelist)
del gc['无'] 
g_sorted = sorted(gc.items(), key=lambda x: x[1], reverse=True)
g_list = [b[0] for b in g_sorted][:30]
g_values = [b[1] for b in g_sorted][:30]
c0 = (
    Pie()
    .add(
        "",
        [list(z) for z in zip(g_list, g_values)],
        radius=["30%", "50%"],
    center=['50%', '60%'],)
    .set_global_opts(title_opts=opts.TitleOpts(title='游戏类型占比饼图'),
                legend_opts=opts.LegendOpts(pos_top="10%")
                )
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")
    )
)
c0.render_notebook()

效果:

Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels

4.2 游戏类型柱状图(横向)

代码:

bar0 = (
    Bar()
    .add_xaxis([b[0] for b in g_sorted])
    .add_yaxis('', [b[1] for b in g_sorted])
    .set_global_opts(
        title_opts=opts.TitleOpts(title='各类游戏数量'),
        yaxis_opts=opts.AxisOpts(name='数量'),
        xaxis_opts=opts.AxisOpts(name='游戏类型'),
        datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(type_='inside')],)
    .set_series_opts( 
        label_opts=opts.LabelOpts(is_show=True),
        markpoint_opts=opts.MarkPointOpts(
            data=[
                opts.MarkPointItem(type_="max", name="最大值"),
                opts.MarkPointItem(type_="min", name="最小值"),
                opts.MarkPointItem(type_="average", name="平均值"),
            ]
        ),
    )
)
bar0.render_notebook()

效果:

Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels


#4.3 Game Type Bar Chart TOP30 (vertical)

Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels

4.4 Rose Chart of Game Advertising Platform Share

# Code:

c0 = (
    Pie()
    .add(
        "",
        [list(z) for z in zip(m_list, m_values)],
        radius=["30%", "50%"],
        rosetype="radius")
    .set_global_opts(title_opts=opts.TitleOpts(title='游戏投放广告平台占比',pos_top="2%"),
                legend_opts=opts.LegendOpts(type_="scroll", pos_left="90%",pos_top="10%",orient="vertical")
                )
    .set_series_opts(label_opts=opts.LabelOpts(
        position="outside",
        formatter="\n {b}:{c}--占比:{d}%"))
    )
c0.render_notebook()
效果:
Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels
可以直观的看到今日头条、抖音、抖音火山版、西瓜视频、穿山甲联盟、腾讯新闻、腾讯QQ等平台游戏广告投放占比比较大,这也是目前比较火热的几个平台,基本符合目前的行情。
4.5 游戏投放媒体平台占比玫瑰图TOP20 
Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels
可以直观的看到游戏投放占比比较大的媒体有信息流广告、信息流视频广告、新闻业广告虎扑、东方头条、悦头条、墨迹天气wait.

##4.6 Distribution of number of game transport companies and media

Code:

l = (
    Line()
    .add_xaxis(df['游戏名称'].values.tolist())
    .add_yaxis("联运公司", df['联运公司'].values.tolist(),color='#ed1941',is_smooth=True,stack='stack1')
    .add_yaxis("投放媒体数目", df['投放媒体数目'].values.tolist(), color='#00ae9d',is_smooth=True,stack='stack1')
    .set_series_opts(
        areastyle_opts=opts.AreaStyleOpts(opacity=0.9),
        label_opts=opts.LabelOpts(is_show=True),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="游戏联运公司与投放媒体数目分布"),
        xaxis_opts=opts.AxisOpts(
            axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
            is_scale=False,
            boundary_gap=False,
        ),
    )
)
l.render_notebook()

效果:

Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels

4.7 广告平台词云 

代码:

w0 = (
    WordCloud()
    .add("", 
         ac.most_common(), 
         word_size_range=[5, 55])
    .set_global_opts(title_opts=opts.TitleOpts(title="广告平台词云"))
)
w0.render_notebook()
效果:
Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels


The above is the detailed content of Pandas + Pyecharts | Comprehensive analysis of ADX game advertising channels. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:Python当打之年. If there is any infringement, please contact admin@php.cn delete