【Python数据可视化】2023中秋国庆电影票房数据

📣 前言

大家好,我是 👉【Python Data实验室】

  • 👓 可视化主要使用 pyecharts、pygal
  • 🔎 数据处理主要使用 pandas
  • Step 1. 导入模块

    import numpy as np
    import pandas as pd
    from pyecharts import options as opts
    from pyecharts.charts import *
    from pyecharts.commons.utils import JsCode
    from pyecharts.globals import ThemeType
    from pyecharts.components import Table
    from pyecharts.globals import ChartType
    from pyecharts.options import ComponentTitleOpts
    from datetime import datetime
    import pygal
    
    #设置pygal与jupyter notebook交互
    from IPython.display import display, HTML
    
    base_html = """
    <!DOCTYPE html>
    <html>
      <head>
      <script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/svg.jquery.js"></script>
      <script type="text/javascript" src="https://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js""></script>
      </head>
      <body>
        <figure>
          {rendered_chart}
        </figure>
      </body>
    </html>
    """

    Step 2. 数据分析可视化

    2.1 影片40+指标票房数据

  • df1 =pd.read_excel(r"影片票房.xlsx")
    df1.head()

  • df1.info()
    
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 7618 entries, 0 to 7617
    Data columns (total 41 columns):
    日期         7618 non-null object
    排名         7618 non-null int64
    电影名称       7618 non-null object
    影片英文名称     7436 non-null object
    当前票房       7618 non-null float64
    累计票房       7618 non-null float64
    累计场次       7618 non-null int64
    累计人次       7618 non-null int64
    票房占比       7618 non-null float64
    当前场次       7618 non-null int64
    当前人次       7618 non-null int64
    人次占比       7618 non-null float64
    累计上映天数     7083 non-null float64
    场均人次       7618 non-null int64
    场均收入       7618 non-null int64
    上映日期       7083 non-null object
    黄金场票房      7618 non-null float64
    黄金场场次      7618 non-null int64
    黄金场人次      7618 non-null int64
    黄金场排座      7618 non-null int64
    黄金场场均人次    7618 non-null int64
    票房环比       7618 non-null float64
    场次环比       7618 non-null float64
    人次环比       7618 non-null float64
    场次占比       7618 non-null float64
    上午场票房      7618 non-null float64
    上午场场次      7618 non-null int64
    上午场人次      7618 non-null int64
    下午场票房      7618 non-null float64
    下午场场次      7618 non-null int64
    下午场人次      7618 non-null int64
    加映场票房      7618 non-null float64
    加映场场次      7618 non-null int64
    加映场人次      7618 non-null int64
    上座率        7618 non-null float64
    黄金场票房占比    7618 non-null float64
    黄金场场次占比    7618 non-null float64
    黄金场人次占比    7618 non-null float64
    黄金场上座率     7618 non-null float64
    当前排座       7618 non-null int64
    排座占比       7618 non-null float64
    dtypes: float64(19), int64(18), object(4)
    memory usage: 2.4+ MB
    res1=df1.groupby('日期').agg({'当前票房':'sum',
                                 '当前场次':'sum',
                                 '当前人次':'sum',
                               }).reset_index() 
    res1['当前票房(千万)'] = res1['当前票房'].apply(lambda x: round(x / 10000000, 2))
    res1['当前场次(万)'] = res1['当前场次'].apply(lambda x: round(x / 10000, 2))
    res1['当前人次(万)'] = res1['当前人次'].apply(lambda x: round(x / 10000, 2))
    res1

  • 全国电影每日票房概览(09-01~10-24)
  • from pygal.style import DarkGreenBlueStyle
    
    line_chart = pygal.Line(x_label_rotation=90,height=300,style=DarkGreenBlueStyle,
                           )
    # 设置平滑线样式  
    line_chart.title = '全国电影每日票房概览(09-01~10-24)'
    line_chart.y_title='当前票房(千万)'
    line_chart.x_labels = res1["日期"].tolist()
    line_chart.add('票房',res1["当前票房(千万)"].tolist())#传入第一组数据
    
    HTML(base_html.format(rendered_chart=line_chart.render(is_unicode=True)))#图片渲染

  • 全国电影每日场次概览(09-01~10-24)
  • 全国电影每日人次概览(09-01~10-24)

筛选中秋国庆数据

data = df1[(df1["日期"] >= "2023-09-28") & (df1["日期"] <= "2023-10-07")]
box_office_sum = data['当前票房'].sum()  
current_session_sum = data['当前场次'].sum()  
current_per_sum = data['当前人次'].sum()

res2=data.groupby('电影名称').agg({'当前票房':'sum',
                             '当前场次':'sum',
                             '当前人次':'sum',
                           }).reset_index()
res2["票房占比"] = res2["当前票房"].apply(lambda x:round(x / box_office_sum, 6) * 100)
res2["场次占比"] = res2["当前场次"].apply(lambda x:round(x / current_session_sum, 6) * 100)
res2["人次占比"] = res2["当前人次"].apply(lambda x:round(x / current_per_sum, 6) * 100)

res2["当前票房"] = res2["当前票房"].apply(lambda x:round(x / 100000000, 4))

# 重命名列名  
res2 = res2.rename(columns={'当前票房': '累计票房(亿)'})

res2[res2["电影名称"] == "坚如磐石"]

中秋国庆档多指标多组图

2.2 影片地域分布



df2 =pd.read_excel(r"/home/mw/input/movie8361/影片地域分布.xlsx")
df2.head()

筛选中秋国庆档数据

data2 = df2[(df2["日期"] >= "2023-09-28") & (df2["日期"] <= "2023-10-07")]

以【'CityLevel', '电影名称'】进行分组

res3 = data2.groupby(['CityLevel', '电影名称']).agg({'当前票房':'sum',  
                             '当前场次':'sum',  
                             '当前人次':'sum',  
                           }).reset_index().sort_values('CityLevel')
res3
筛选城市级别
one_city = res3[(res3['CityLevel'] == '一线城市')]
two_city = res3[(res3['CityLevel'] == '二线城市')]
three_city = res3[(res3['CityLevel'] == '三线城市')]
four_city = res3[(res3['CityLevel'] == '四线城市') ]
five_city = res3[(res3['CityLevel'] == '其它')]

one_city = one_city.drop(columns='CityLevel')  
two_city = two_city.drop(columns='CityLevel')  
three_city = three_city.drop(columns='CityLevel')  
four_city = four_city.drop(columns='CityLevel')  
five_city = five_city.drop(columns='CityLevel')  
one_city_movie = one_city.rename(columns = {'当前场次': '一线城市场次','当前票房': '一线城票房','当前人次': '一线城人次'})

重组连接数据

two_city_movie = two_city.rename(columns = {'当前场次': '二线城市场次','当前票房': '二线城票房','当前人次': '二线城人次'})
three_city_movie = three_city.rename(columns = {'当前场次': '三线城市场次','当前票房': '三线城票房','当前人次': '三线城人次'})
four_city_movie = four_city.rename(columns = {'当前场次': '四线城市场次','当前票房': '四线城票房','当前人次': '四线城人次'})
five_city_movie = five_city.rename(columns = {'当前场次': '其它城市场次','当前票房': '其它城票房','当前人次': '其它城人次'})


move_top_10 = one_city_movie.merge(two_city_movie, how='left', on='电影名称').fillna(0)
move_top_10 = move_top_10.merge(three_city_movie, how='left', on='电影名称').fillna(0)
move_top_10 = move_top_10.merge(four_city_movie, how='left', on='电影名称').fillna(0)
move_top_10 = move_top_10.merge(five_city_movie, how='left', on='电影名称').fillna(0)
move_top_10
2023年中秋国庆档电影票房地域分布(场次)-top10影片

2023年中秋国庆档电影票房地域分布(人次)-top10影片

2023年中秋国庆档电影票房地域分布(票房)-top10影片

数据集链接👇

【电影票房】电影每日电影40+指标数据 ​

 可视化项目源码👇

【电影】Python数据可视化2023中秋国庆电影票房数据

🤓🥺😚感谢支持,原创不易,如果觉得此项目还可以希望可以给我点赞、收藏也可以分享(注明出处)。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值