? ? ? 大家好,我是带我去滑雪!
? ? ? 分析电影票房数据具有多个优点:首先通过分析票房数据,可以深入了解观众的喜好和趋势。了解哪些类型的电影在特定时期或地区更受欢迎,有助于电影制片人更好地满足观众的需求,制定更有针对性的电影制作计划。其次,通过分析票房数据,制片公司可以更好地了解哪些市场渠道和宣传手段对提高电影知名度和票房收入最为有效。这有助于精确制定市场营销策略,最大化投资回报。下面开始实战,爬取影院名称,当周票房、单荧幕票房、场均人次、单日单厅票房、单日单厅场次6个变量并进行数据分析。
import urllib
import requests
from fake_useragent import UserAgent
import json
import pandas as pd
import time
import datetime
comment_api = 'http://www.cbooo.cn/BoxOffice/getCBW?pIndex={}&dt={}'
headers = { "User-Agent": UserAgent(verify_ssl=False).random}
col = ['cinemaName','amount','avgPS','avgScreen','scenes_time','screen_yield']
dataall = pd.DataFrame()
num = 1035
for i in range(1,num+1):
response_comment = requests.get(comment_api.format(i,1041),headers = headers)
json_comment = response_comment.text
json_comment = json.loads(json_comment)
n = len(json_comment['data1'])
datas = pd.DataFrame(index = range(n),columns = col)
for j in range(n):
datas.loc[j,'cinemaName'] = json_comment['data1'][j]['cinemaName']
datas.loc[j,'amount'] = json_comment['data1'][j]['amount']
datas.loc[j,'avgPS'] = json_comment['data1'][j]['avgPS']
datas.loc[j,'avgScreen'] = json_comment['data1'][j]['avgScreen']
datas.loc[j,'scenes_time'] = json_comment['data1'][j]['scenes_time']
datas.loc[j,'screen_yield'] = json_comment['data1'][j]['screen_yield']
dataall = pd.concat([dataall,datas],axis = 0)
print('完成进度 {}% !'.format(round(i/num*100,2)))
time.sleep(0.5)
dataall = dataall.reset_index()
爬取结果展示:
import os
import pandas as pd
import numpy as np
import jieba
import jieba.analyse
import jieba.posseg
import cpca
import matplotlib.pyplot as plt
from pyecharts.charts import Map
from pyecharts.charts import Geo
from pyecharts.charts import Bar
from pyecharts.charts import Boxplot
import seaborn as sns
data1 = pd.read_excel('data1.xlsx')
data2 = pd.read_excel('data2.xlsx')
data1 = data1.drop_duplicates()
data2 = data2.drop_duplicates()
datas = pd.merge(data1,data2,left_on ='cinemaName',right_on = 'cinemaName').dropna()
datas = datas.reset_index(drop = True)
dataall = datas[['cinemaName']]
dataall['amount'] = datas['amount_x'] + datas['amount_y']
dataall['avgPS'] = (datas['avgPS_x'] + datas['avgPS_y'])/2
dataall['avgScreen'] = datas['avgScreen_x'] + datas['avgScreen_y']
dataall['screen_yield'] = (datas['screen_yield_x'] + datas['screen_yield_y'])/2
dataall['scenes_time'] = (datas['scenes_time_x'] + datas['scenes_time_y'])/2
dataall['avgprice'] = dataall.screen_yield/dataall.scenes_time/dataall.avgPS
dataall = dataall.dropna().reset_index(drop = True)
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
dataall['票房'] = np.log10(dataall.amount)
plt.figure(figsize = (10,5))
plt.scatter(dataall.avgprice,dataall.avgPS,c = dataall.票房,cmap ='YlGnBu' ,s = 10)
plt.xlabel('平均票价')
plt.ylabel('场均人次')
plt.colorbar(label = '票房')
plt.show()
sns.pairplot(dataall,diag_kind = 'kde')
plt.how()
结果展示:
? ? ? ?通过上图可以发现:票价,场均人次与票房之间关系如图,颜色越深,表明票房越高。票价影响场均人次,过高和过低都会使票房收入减少,平均票价40-70区间内,影院票房收入更高,符合实际情况。
? ? ? 通过上图可以看出,所有变量都呈现尖峰右拖尾的特征,大部分值低于中位数,但也不乏高于均值的点,考虑到各个影院数据存在规模、地域等因素差异。
需要数据集的家人们可以去百度网盘(永久有效)获取:
链接:https://pan.baidu.com/s/173deLlgLYUz789M3KHYw-Q?pwd=0ly6
提取码:2138?
更多优质内容持续发布中,请移步主页查看。
若有问题可邮箱联系:1736732074@qq.com?
博主的WeChat:TCB1736732074
? ?点赞+关注,下次不迷路!