第11章综合案例2影评大数据分析

article/2025/11/8 7:33:21

第11章综合案例2影评大数据分析

实验目的及要求

(1)现有电影、影评和用户信息3个数据文件,将对其进行大数据分析。

实验系统环境及版本

  1. Linux Ubuntu 20.04

  2. JDK1.8

  3. Hadoop3.1.0

  4. MySQL8.0.28

  5. Hive3.1.2

实验任务

  1. 评分次数最多的10部电影;

  2. 性别当中评分最高的10部电影;

  3. 一部电影各年龄段的平均影评;

  4. 评分最高的10部电影的平均评分;

  5. 好片最多年份的最好看电影Top10;

  6. 评分最高的10部Comedy类电影;

  7. 各种类型电影中评价最高的5部电影。

实验内容及步骤

创建一个数据仓库movie

hive> create database movie;

hive> use movie;

在这里插入图片描述

创建t_user表及导入数据

hive> create table t_user(userid bigint,sex string,age int,occupation string,zipcode string) row format delimited fields terminated by ‘\t’;

在这里插入图片描述

hive> load data local inpath ‘/opt/datas/user.txt’ into table t_user;

在这里插入图片描述

创建t_movie表及导入数据

hive> create table t_movie(movieid bigint,moviename string,movietype string) row format delimited fields terminated by ‘\t’;

hive> load data local inpath ‘/opt/datas/movie.txt’ into table t_movie;

在这里插入图片描述

创建t_ratings表及导入数据

hive> create table t_ratings(

> userid bigint,

> movieid bigint,

> rate double,

> times string)

> row format serde ‘org.apache.hadoop.hive.serde2.RegexSerDe’

> stored as textfile;

在这里插入图片描述

hive> load data local inpath “/opt/datas/ratings.dat” into table t_ratings;

在这里插入图片描述

基本信息查询

查询表t_user的记录总数:

hive> select count( *) from t_user;

在这里插入图片描述

查询表t_movie的记录总数:

hive> select count( *) from t_movie;
在这里插入图片描述

查询表t_rating的记录总数:

hive> select count( *) from t_ratings;

在这里插入图片描述

查看3个表文件的数据大小:

hdfs dfs -du -h /user/hive/warehouse/movie.db/t_movie

hdfs dfs -du -h /user/hive/warehouse/movie.db/t_user

hdfs dfs -du -h /user/hive/warehouse/movie.db/t_ratings
在这里插入图片描述

1.评分次数最多的10部电影

统计评分次数最多的10部电影,并给出评分次数(电影名、评分次数)。

按照电影名进行分组统计,求出每部电影的评分次数并按照评分次数降序排序,保存在表answer2中:

hive> create table answer2 as

> select a.moviename as moviename,count(a.moviename) as total from t_movie a join t_ratings b on a.movieid=b.movieid

> group by a.moviename order by total desc limit 10;

在这里插入图片描述

查询表answer2:

hive> select * from answer2;

在这里插入图片描述

2.性别当中评分最高的10部电影

统计男性、女性当中评分最高的10部电影(性别、电影名、影评分)。

(1)创建表answer3_F,保存女性当中评分最高的10部电影(性别、电影名、影评分),分组条件为评论次数大于或等于50次:

create table answer3_F as

select “F” as sex, c.moviename as name, avg(a.rate) as avgrate, count(c.moviename) as total

from t_ratings a join t_user b on a.userid=b.userid

join t_movie c on a.movieid=c.movieid

where b.sex=“F”

group by c.moviename

having total >= 50

order by avgrate desc

limit 10;

在这里插入图片描述

(2)查询表answer3_F:

select sex,name,round(avgrate,2),total from answer3_F;

在这里插入图片描述

(3)创建表answer3_M,保存男性当中评分最高的10部电影(性别、电影名、影评分),要求评论次数大于或等于50次:

create table answer3_M as

select “M” as sex, c.moviename as name, avg(a.rate) as avgrate, count(c.moviename) as total

from t_ratings a join t_user b on a.userid=b.userid

join t_movie c on a.movieid=c.movieid

where b.sex=“M”

group by c.moviename

having total >= 50

order by avgrate desc

limit 10;

在这里插入图片描述

(4)查询表answer3_M:

select sex,name,round(avgrate,2),total from answer3_M;

在这里插入图片描述

2.一部电影各年龄段的平均影评

统计movieid = 2116这部电影各年龄段的平均影评(年龄段、影评分)。

(1)对t_user和t_ratings表进行联合查询,用movieid=2116作为过滤条件,用年龄段作为分组条件,查询结果保存在表answer4中:

create table answer4 as

select a.age as age, avg(b.rate) as avgrate

from t_user a join t_ratings b on a.userid=b.userid

where b.movieid=2116

group by a.age;

在这里插入图片描述

(2)查询表answer4:

select age,round(avgrate,2) from answer4;

在这里插入图片描述

3.评分最高的10部电影的平均影评分

统计最喜欢看电影(影评次数最多)的那位女性评分最高的10部电影的平均影评分(观影者、电影名、影评分)。

(1)查询最喜欢看电影的那位女性,查询的字段分别为t_user.sex(性别)和count t_ratings.userid(观影次数):

select a.userid, count(a.userid) as total

from t_ratings a join t_user b on a.userid = b.userid

where b.sex=“F”

group by a.userid

order by total desc

limit 10;

在这里插入图片描述

(2)根据上述(1)中查询的女性userid作为Where过滤条件,以看过的电影的影评分rate作为排序条件进行排序,统计出评分最高的10部电影,并将查询结果保存在表answer5_B中:

create table answer5_B as

select a.movieid as movieid, a.rate as rate

from t_ratings a

where a.userid=1150

order by rate desc

limit 10;

在这里插入图片描述

(3)查询表answer5_B:

select * from answer5_B;

在这里插入图片描述

(4)统计上述(3)中10部电影的平均影评分,需要查询的字段分别为answer5_B.movieid(电影的ID)和t_ratings.rate(影评分),并将查询结果保存在表answer5_C中:

create table answer5_C as

select b.movieid as movieid, c.moviename as moviename, avg(b.rate) as avgrate

from answer5_B a join t_ratings b on a.movieid=b.movieid

join t_movie c on b.movieid=c.movieid

group by b.movieid,c.moviename;

在这里插入图片描述

(5)查询表answer5_C:

select movieid,moviename,round(avgrate,2) from answer5_C;

在这里插入图片描述

4.好片最多年份的最好看电影Top10

年份的最好看电影Top10。

(1)将t_rating和t_movie表进行联合查询,截取电影名中的上映年份,并将查询结果保存至表answer6_A:

create table answer6_A as select

a.movieid as movieid, a.moviename as moviename,

substr(a.moviename,-5,4) as years, avg(b.rate) as avgrate

from t_movie a join t_ratings b on a.movieid=b.movieid

group by a.movieid, a.moviename;
在这里插入图片描述

(2)查询表answer6_A:

select * from answer6_A;

在这里插入图片描述
在这里插入图片描述

(3)按照年份将answer6_A分组,评分≥4.0作为过滤条件,按照count(years)作为排序条件进行查询:

select years, count(years) as total

from answer6_A a

where avgrate >= 4.0

group by years

order by total desc

limit 10;

在这里插入图片描述

(4)按照years=1998作为Where过滤条件,按照评分作为排序条件进行查询,并保存至表answer6_C:

create table answer6_C as

select a.moviename as name, a.avgrate as rate

from answer6_A a

where a.years=1998

order by rate desc

limit 10;
在这里插入图片描述

(5)查询表answer6_C:

select name,round(rate,2) from answer6_C;

在这里插入图片描述

5.评分最高的10部Comedy类电影

统计1997年上映的电影中评分最高的10部Comedy类电影。

(1)将answer6_A表和t_movie表进行联合查询,保存至表answer7_A:

create table answer7_A as

select b.movieid as id, b.moviename as name, b.years as years, b.avgrate as rate, a.movietype as type

from t_movie a join answer6_A b on a.movieid=b.movieid;

在这里插入图片描述

(2)表answer7_A按照电影类型中是否包含Comedy和按照评分≥4.0作为Where过滤条件,按照评分作为排序条件进行查询,将结果保存到表answer7_B中。其中,instr函数返回字符串str中子字符串substr第一次出现的位置,在SQL中第一字符的位置是1,如果str不含substr,则返回0。lcase函数把字段的值转换为小写。

create table answer7_B as

select t.id as id, t.name as name, t.rate as rate

from answer7_A t

where t.years=1997 and instr(lcase(t.type),‘comedy’) >0

order by rate desc

limit 10;

在这里插入图片描述

(3)查询表answer7_B:

select id,name,round(rate,2) from answer7_B;
在这里插入图片描述

6.各种类型电影中评价最高的5部电影

统计各种类型电影中评价最高的5部电影(类型、电影名、平均影评分)。

(1)将表answer7_A中的type字段进行裂变,将结果保存到表answer8_A中。其中,Lateral View用于和Split、Explode等函数一起使用,能将一行数据拆分成多行数据,在此基础上可以对拆分的数据进行聚合。Lateral View首先为原始表的每行调用UDTF,UDTF会把一行拆分成一行或者多行,Lateral View再把结果组合,产生一个支持别名表的虚拟表。

create table answer8_A as

select a.id as id, a.name as name, a.years as years, a.rate as rate, tv.type as type

from answer7_A a

lateral view explode(split(a.type,“\\|”)) tv as type;

在这里插入图片描述

(2)查询表answer8_A:

select * from answer8_A limit 10 ;

在这里插入图片描述

(3)按照type分组,添加一列记录每组的顺序,将结果保存到表answer8_B中:

create table answer8_B as

select id,name,years,rate,type,row_number() over(distribute by type sort by rate desc ) as num

from answer8_A;

在这里插入图片描述

(4)查询表answer8_B:

select * from answer8_B limit 10;

在这里插入图片描述

(5)从表answer8_B中取出num列序号≤5:

select a.id, a.name, a.years, round(a.rate,2), a.type, a.num from answer8_B a where a.num <= 5 limit 10;
在这里插入图片描述


http://chatgpt.dhexx.cn/article/2nVQ2SJM.shtml

相关文章

淘宝大数据分析案例

项目介绍 本次结合的是一份淘宝大数据数据&#xff0c;数据集的大小共177MB&#xff0c;数据一共有3182261份&#xff08;三百多万份数据集&#xff09;&#xff0c;一般的软件是无法计算和分析的&#xff0c;比如Excel&#xff0c;MySQL&#xff0c;Python这些都无法较好的完…

数据分析综合案例

数据分析综合案例&#xff1a; 数据分析流程 什么是数据清洗&#xff1f; 简单来说&#xff0c;数据清洗就是把“脏数据”变为“干净的数据”。数据清洗虽然很繁琐&#xff0c;但也很重要。数据清洗流程&#xff1a; 数据的读写、数据的探索与描述、数据简单处理、重复值的处…

磁力搜索网站+下载神器放送2019-03-05

先介绍下背景,因为喜欢看的电影因为版权问题,不能用迅雷及百度云离线下载.今天找了好久,终于发现了一个好用的解决方案. 先介绍常用的磁力搜索网站: 搜索网 https://btsow.pw/tags https://cn.torrentkitty.tv https://www.ciliurl.com/ http://www.zhizhuc.com/ https://www.a…

几款磁力搜索引擎,找资料更方便

Bt177.info 一款强大的磁力搜索引擎网站&#xff0c;这款网站包含有7万多个磁力链接&#xff0c;提供提供网盘形式和磁力形式的储存&#xff0c;有很多你想要的东西。如果是音频和视频的话支持在线观看。 Bt977 磁力搜索引擎&#xff0c;支持网盘播放&#xff0c;磁力下载。 To…

搜索下载神器

前言 新闪存云app是一款功能非常强大的云盘软件&#xff0c;为用户提供了非常给力资源搜索功能&#xff0c;支持多种下载方式&#xff0c;让你在这里体验全网最快速的资源下载&#xff0c;多种格式的文件以及视频也都可以在这里进行下载并进行解析&#xff0c;操作十分的简单&a…

基于python的种子搜索网站,你懂得!

该项目是基于python的web类库django开发的一套web网站&#xff0c;给师弟做的毕业设计。本人的研究方向是一项关于搜索的研究项目。在该项目中&#xff0c;笔者开发了一个简单版的搜索网站&#xff0c;实现了对数据库数据的检索和更新。通过开发该项目&#xff0c;笔者学习和巩…

android下载工具 磁力,【安卓+iOS】磁力搜索+下载工具

【安卓iOS】磁力搜索下载工具 2020-03-29 19:46:20 3点赞 16收藏 2评论 1、比特舟Pro(安卓) 比特舟Pro是一款磁力搜索工具&#xff0c;支持BT和磁力搜索。前身是比特羊&#xff0c;后来改名比特知了&#xff0c;现在又一此改名。名字虽然变了&#xff0c;功能还是一样。 想搜什…

Ubuntu 能直接搜 BT 种子了

Ubuntu的Dash搜索工具允许用户搜索本地和在线资源如亚马逊和维基百科上的内容。现在&#xff0c;一位第三方开发者为Dash搜索工具加入了BT搜索功能&#xff0c;允许用户搜索海盗湾上的torrent文件。这项功能获得了 Canonical 创始人Mark Shuttleworth的支持。 Canonical表示&am…

利用Python爬虫建立自己的磁力搜索引擎

现在磁力站很多,但是搜出来的东西乱七八糟的,广告也多,我看多了觉得挺烦的,正好周末无聊,想着自己做一个,下面附上本次利用Python爬虫磁力站点的教程。 下面是我写爬虫时候主要引用的库 当然,抓取的关键词可以自己从代码里设置,比如title,文件大小之类的。 但我怎么知…

TT盒子种子搜索神器

2、软件名称&#xff1a;tt盒子种子搜索神器 3、软件版本&#xff1a;V1.5 4、软件大小&#xff1a;2.31MB 5、软件作者及网址&#xff1a;TT盒子 网站&#xff1a;www.tthezi.com 6、软件类别&#xff1a;搜索引擎 7、软件语言&#xff1a;简体中文 8、软件授权&#xff1a;免…

想做个磁力链搜索引擎 3

上一篇中&#xff0c;我们已经实现了对tracker的访问&#xff0c;从而获取到了peer对等体的ip地址以及端口号。我们这一篇要实现的是对等体之间的通讯。 在bt种子下载中&#xff0c;对等体就是正在下载你需要文件的另一台主机或提供下载你需要文件的主机。每一个种子一开始都是…

[搜片神器]直接从DHT网络下载BT种子的方法

转自:http://www.cnblogs.com/miao31/p/3332819.html DHT抓取程序开源地址:https://github.com/h31h31/H31DHTDEMO 数据处理程序开源地址:https://github.com/h31h31/H31DHTMgr DHT系列文章: 1.[搜片神器] 之P2P中DHT网络爬虫原理 2.[搜片神器]之DHT网络爬虫的代码实现方法…

P2P下载器-P2P种子搜索器

P2P种子搜索器(p2psearcher)是一款集种子搜索器和在线云点播于一身的实用工具&#xff0c;基于先进的P2P搜索技术&#xff0c;可在瞬间搜遍全球ED2k网络资源。p2psearcher搜到的视频资源可以直接在右侧的云点播播放页面试播预览&#xff0c;并且提供高品质观影效果。需要的朋友…

这才是CSDN最系统的网络安全学习路线(建议收藏)

01 什么是网络安全 网络安全可以基于攻击和防御视角来分类&#xff0c;我们经常听到的 “红队”、“渗透测试” 等就是研究攻击技术&#xff0c;而“蓝队”、“安全运营”、“安全运维”则研究防御技术。 无论网络、Web、移动、桌面、云等哪个领域&#xff0c;都有攻与防两面…

网络安全学习资源分享

提高技能 网络安全学习资源汇总 项目描述OWASP安全的牧羊人&#xff08;https://security-shepherd.ctf365.com/login.jsp&#xff09;作为11/6破ctflearn&#xff08;https://ctflearn.com/&#xff09;基于CTF网站账户&#xff0c;用户可以在解决一系列挑战ctfs写-不间断电…

网络安全学习路线,入门到入坟,史上最全网络安全学习路线整理

很多小伙伴在网上搜索网络安全时&#xff0c;会出来网络安全工程师这样一个职位&#xff0c;它的范围很广&#xff0c;只要是与网络安全挂钩的技术人员都算网络安全工程师&#xff0c;一些小伙伴就有疑问了&#xff0c;网络安全现在真的很火吗&#xff1f; 那么寒哥就带大家看…

网络安全学习:安全学习

特别有用 赶脚,,,赶脚,,,这组比较像,,,因为响应头带了个audio&#xff0c;再巴拉开响应头看看&#xff1a; 就是你了 /20170407233726/7bcb1a38c8e959f677b58519ac8a2958/ymusic/9c2b/57dd/26dc/df6def971d6cdd160d347dcb6a1c18f4.mp3 之后就不在C盘的缓存文件夹里巴拉了&…

网络安全(黑客)学习路线

目录 背景 那么要怎么才能成为一名黑客呢&#xff1f; &#xff08;1&#xff09;基础部分 ​编辑&#xff08;1.1&#xff09;计算机网络 &#xff1a; &#xff08;1.2&#xff09;Linux 系统及命令 &#xff1a; &#xff08;1.3&#xff09;Web 框架 &#xff1a; &…

网络安全学习路线

如何成为一名黑客,很多朋友在学习安全方面都会半路转行,因为不知如何去学,今天在知乎看到个不错的,果断收藏学习下路线。此篇博课讲的非常细,有兴趣的同学可以参考。 关于黑客或网络安全如何入门和学习路径,我在去年的问答和专栏中也陆陆续续解读过,近期知乎时间线上又…

网络安全学习篇

提示&#xff1a;学习网络安全&#xff0c;了解网络知识 文章目录 (一)虚拟机环境搭建01虚拟机概述传统运行模式虚拟机运行架构1.寄生架构 &#xff08;实验环境、测试环境&#xff09;2.原生架构&#xff08;生产环境&#xff09; 虚拟机平台产品FTP服务器 02虚拟机管理2.1关闭…